- Home /
How to get the accurate speed of a car with wheelcolliders?
I am making a simple car driving game and made a guiText for displaying the speed of the car. When I play the game in Unity Editor, everything seem to work well except for that the speed displayed doesn't seem very realistic (my car doesn't look like it's going that fast). The car drives on roads that have lane markings and stuff so I can tell that it is going too fast. Here is my code for calculating the speed. currentSpeed = Mathf.Round(2*22/7*wheelRL.radius*wheelRL.rpm*60/1000); I put realistic numbers for the wheel radius in the wheelcollider.
Answer by EvilTak · Jan 03, 2015 at 04:43 PM
Simply get the correct speed by using rigidbody.velocity.magnitude. It returns the speed in M/S. To get the speed in KM/H multiply the magnitude by 3.6f, and to get it in M/H multiply the magnitude by 2.237f. You don't need to do such calculations using wheelcolliders.
This is not accurate, as this will give the speed of the rigidbody REGARDLESS of whether you are connected to the ground and REGARDLESS of whether you are moving forward or sideways.
To get an accurate reading you do in fact need to calculate it from a wheel's angular velocity.
Your answer