Answers for "how to keep rigidbody2D upright unity"

C#
0

how to keep rigidbody2D upright unity

Rigidbody hoverRB; // hovercraft's rigidbody

...

void FixedUpdate() 
{    
    Quaternion deltaQuat = Quaternion.FromToRotation(hoverRB.transform.up, Vector3.up);

    Vector3 axis;
    float angle
    deltaQuat.ToAngleAxis(out angle, out axis);

    float dampenFactor = 0.8f; // this value requires tuning
    hoverRB.AddTorque(-hoverRB.angularVelocity * dampenFactor, ForceMode.Acceleration);

    float adjustFactor = 0.5f; // this value requires tuning
    hoverRB.AddTorque(axis.normalized * angle * adjustFactor, ForceMode.Acceleration);
}
Posted by: Guest on September-05-2021

Code answers related to "how to keep rigidbody2D upright unity"

C# Answers by Framework

Browse Popular Code Answers by Language