# onClientVehicleCollision problem

## Recommended Posts

I got my other scripts to work, so I think it should be okay if I asked for some help here.

I want to get vehicle's speed before he hits another vehicle, the problem is, it always returns the same speed (180 or 179kph), no matter how fast or slow I'm going. What I'm doing wrong here?

http://wiki.multitheftauto.com/wiki/OnC ... eCollision

```function collision(collider,force, bodyPart, x, y, z, vx, vy, vz)
if (getElementType (collider) == "vehicle") and (source == getPedOccupiedVehicle (getLocalPlayer())) then
actualspeed = (vx^2 + vy^2 + vz^2)^(0.5)
kmh = actualspeed * 180
outputChatBox(kmh)
end
end
```

But that event is triggered on collision, how do you expect to get the speed before hit on the event that is triggered on collision?

But that event is triggered on collision, how do you expect to get the speed before hit on the event that is triggered on collision?

read the wiki, it says :

velocityX: the X velocity of the source before the collision took place

velocityY: the Y velocity of the source before the collision took place

velocityZ: the Z velocity of the source before the collision took place

```function collision ( collider, force, bodyPart, x, y, z, vx, vy, vz )
if (getElementType (collider) == "vehicle") and (source == getPedOccupiedVehicle (getLocalPlayer())) then
actualspeed = ( vx ^ 2 + vy ^ 2 + vz ^ 2 ) ^ 0.5 * 1.61 * 100
outputChatBox ( actualspeed )
end
end
```

I copied how getElementSpeed function works, try it.

@Solidsnake14

got the same result (but 160/161kph this time), I guess it's bugged, or something else must be done. Thanks anyways

## Create an account

Register a new account