I am making 2D side-scrolling racing game. My character which is rigidbody2D moving on non-flat platform, and I applied addForce to move it. Also I figured out how to limit rotation of the character on Z-axis, but I am completely unsatisfied with the result. The problem is that when character reaches edge of the rotation limit, it just stacks at this angle and no more rotation is occured . How to return the character to its first state when its rotation is calculated by physic engine?
Thanks in advance.
void Update ()
{
rigidbody2D.AddForce(force);
curAngle = rigidbody2D.rotation;
LimitRotation();
}
void LimitRotation()
{
if (curAngle > 45)
{
rigidbody2D.rotation = 45;
}
if(curAngle < - 45 )
{
rigidbody2D.rotation = -45;
}
}