- Home /
AngryBots like character rotation system
Hey guys. I'm trying to make a character rotation system like AngryBot. When you're not moving, if you rotate you char, the torso will rotate 'til a certain amount of degrees and just then the legs will 'adjust' to the rotation of the torso.
I could make a system like this, but the problem is with the smooth rotation when adjusting. I'm actually adding de difference rotation between torso and legs to the legs with Math.Lerp, but the problem is when the rotation need to reset, I mean, is close to 360 and need to reach a low value, like 10, then the legs rotate in the wrong direction to reach the torso rotation. This only happens when it need to pass through 360 to reach a low value.
Did you guys would have an idea about how can I make it rotate correctly?
Thanks from now!
*Here's the small piece of code I'm using to adjust the rotation:
IEnumerator correctRotation(float lerpSpeed) {
float rotationBody = Head.eulerAngles.y - Body.eulerAngles.y;
float rotationLeg = Head.eulerAngles.y - Leg.eulerAngles.y;
if(Mathf.Abs(Leg.eulerAngles.y - Head.eulerAngles.y) > 5) {
Body.eulerAngles = new Vector3(Body.eulerAngles.x, Mathf.Lerp(Body.eulerAngles.y, (Body.eulerAngles.y + rotationBody), lerpSpeed), Body.eulerAngles.z);
Leg.eulerAngles = new Vector3(Leg.eulerAngles.x, Mathf.Lerp(Leg.eulerAngles.y, (Leg.eulerAngles.y + rotationLeg), lerpSpeed), Leg.eulerAngles.z);
permitRotation = false;
} else {
permitRotation = true;
}
yield return new WaitForEndOfFrame();
}