I want to know what the right formula is, or a way to make the wheels rotate with the speed of the vehicle? What is the standard way to make wheels look realistic and natural? Do developers use other techniques?
Thank you for helping
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It only takes a minute to sign up.
Sign up to join this communityWhen you are using the Unity physics system, the engine offers you a WheelCollider which handles wheel physics for you.
Usual practice is that the wheel colliders are not attached to the wheel mesh but rather to the vehicle body directly. So they are supposed to simulate "invisible" wheels. You then control the vehicle by changing the motorTorque, brakeTorque and steerAngle of each wheel and let the physics engine do the rest.
You can then use wheelCollider.GetWorldPose() to get the current position and rotation of each simulated wheel and assign these to the visible but non-physical wheel models.
The idea is that you need to have the outer part of the wheel go on the ground at the same speed that the one of the vehicle.
Assuming you have these values beforehand:
vehicle_speed // in meters per second
wheel_radius // in meters
You can infer this one:
wheel_circumference = 2 * PI * wheel_radius // still in meters
You can then get the rotation per second for the wheels:
rot_per_second = vehicle_speed / wheel_circumference
Now, this will not take into consideration the fact that the front wheels will turn on the vertical axis to make the vehicle steer, and that the inside wheels will roll less than the outside ones when the vehicle steer. It is, however, enough for you to simulate the wheels animation on your vehicle.