Getting speed of object

Hi. I’d like to add a speedometer to my driving sim, but I don’t know how to find out
what speed the car is travelling at.
Anyone know how to find out the speed of an object?

Thanks in advance.

How are you moving your car in the first place? If you have a velocity vector, then the speed of the vehicle should simply be the length of that vector. If you have separate x- and y- (or x-, y-, and z-) velocity values, then simply make a vector of them and get the length of that.

If you don’t have access to the velocity of your car, you could perhaps measure the distance that it has moved since the last frame and use the formula “speed = distance/time” to find the speed. The following outline should work in most cases, I imagine:

  • Store the car’s previous position (updated at the end of the frame, or after the following calculations)
  • Subtract this previous position from the car’s current position, producing a vector that describes the car’s displacement (its change in position) since the last frame
  • Get the distance moved, being the length of the displacement vector just calculated
  • Finally, speed = distance/dt, where “dt” is the time since the last frame.

Thanks for your help, but I found out that I could just do getCurrentSpeedKmHour () on bullet vehicles.