Is there a way to keep vehicle from flipping when jumped from ramp?

Viewed 53

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?

3 Answers

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.

I have the following suggestion for solving your problem. Shortly, you gradually increase the pitch while in the air.

private IEnumerator RotationSequence()
{
    while (!grounded)
    {
        Quaternion deltaRotation = Quaternion.Euler(m_EulerAngleVelocity * Time.fixedDeltaTime);
        rigidBody.MoveRotation(rigidbody.rotation * deltaRotation);
        yield return new WaitForFixedUpdate();
    }
}

maybe you could set the pivot of the car to a different place while its in midair

Related