I'm trying to make a stunt game where vehicle will jump from ramps but unfortunately it keeps leaning forward when in air which makes bad landing I have struggled but can't stop it from doing this. I'm using RCC V3 for car.
vehicle.transform.rotation = Quaternion.Lerp(vehicle.transform.rotation, Quaternion.Euler(-5f, vehicle.transform.rotation.y, vehicle.transform.rotation.z), Time.deltaTime * 2f);
I have used this line of code which stops it from leaning forward but vehicle.transform.rotation.y
this doesn't working properly which makes the car to rotate 180 degree on y axis.
can anyone please help me with it?
CodePudding user response:
You can try with the following:
m_Rigidbody.freezeRotation = true;
when your car is flying, then you can set to false when it's landed.
CodePudding user response:
I have the following suggestion for solving your problem. Shortly, you gradually increase the pitch while in the air.
private IEnumerator RotationSequence(float rotationSpeedDegrees)
{
Vector3 euler = transform.localEulerAngles;
while(!grounded)
{
euler.x = rotaitionSpeedDegrees * Time.deltaTime;
transform.localEulerAngles = euler;
yield return null;
}
}