I’m editing the CarController script beta standard asset’s that Unity has published.
In the PreserveDirectionInAir() method, it has the following code:
rigidbody.MoveRotation(Quaternion.Slerp(rigidbody.rotation, Quaternion.LookRotation(rigidbody.velocity),
Time.deltaTime)); rigidbody.angularVelocity =
Vector3.Lerp(rigidbody.angularVelocity, enter code here`Vector3.zero, Time.deltaTime);
That makes the car rotate in the angle that the car is moving. I basically want to restrict it to only rotate on the cars X axis (so it will stay flat).
My first thought was to just make it Slerp to a Quaternion which had the Y and Z set to the rigidbody.rotation.y and z, and then leave it to rotate towards the x of rigidbody.velocity.
However, that fails because then I’m limiting the global Y and Z axis, not the local - I think anyway.
Any ideas?
Thanks!
To explain the question a bit more, the model looks like this:

And in that image all rotations are zeroed.
While in the air I need to limit the rotation of the car to only the Y axis (in this case the yellow line) - which would be the plane that the wheels are on.
I can achieve that by using the Freeze Rotation constraints for Y.
However as soon as the car is facing a different angle, that fails because the “Y” axis is no longer the right one.

I still need to limit it along that yellow line in this image, however the yellow line is local rotation, not global, and I can only seem to lock it on the global axis’.