My animation settings look like that if I want the rotation from animation update gameobject’s rotation as well. Right now Im expiriecing strange behaviour that each animation ends with different Y rotation, start value is 90, but after animation it become 235.5 236.2 and etc. This is really weird. I also dont see any effect from checking ‘Root transform position Y/XZ’, after animation finishes there are small changes(0.02-0.08 at character’s X and Z coordinates)
I found the way to achieve desired behaviour by disabling ‘Apply root motion’ at animator, and turning character myself by coroutine during animation.
It looks smth like that:
IEnumerator MoveAtDirectionToDistance(Vector2 direction, float distance, float speed, bool makeTurn = false) {
if (makeTurn) {
status.Right180Turn();
float turnTime = 0.8165f;
float endRotation = direction == Vector2.right ? rightDirectionRotation.y: leftDirectionRotation.y;
yield return StartCoroutineAndStopCurrent(Rotate(turnTime, endRotation));
}
status.Walk();
yield return StartCoroutineAndStopCurrent(Move(direction.normalized, distance, speed));
status.Stay();
}
IEnumerator Rotate(float duration, float endRotation) {
float startRotation = transform.eulerAngles.y;
float t = 0.0f;
while (t < duration) {
t += Time.deltaTime;
float yRotation = Mathf.Lerp(startRotation, endRotation, t / duration) % 360.0f;
transform.eulerAngles = new Vector3(transform.eulerAngles.x, yRotation, transform.eulerAngles.z);
yield return null;
}
}
void Update() {
CheckMovementAnimation(0);
}
void CheckMovementAnimation(int layer) {
if (status.isWalk) {
Play(Animations.WALK, layer, false, false, 0.05f);
} else if (status.isStay) {
Play(Animations.IDLE, layer, false, false);
} else if (status.isRight180Turn) {
Play(Animations.RIGHT_180_TURN, layer, false, false);
}
This method will update character status to ‘turn’ state, Update method will trigger animation via animator and CrossFade method, and after updating character status first method will run coroutine to rotate gameobjects
This solution doesnt looks good for me, but it makes position and rotation of characters fully expected after animation is played, hope for your advices to achieve same result in better ways 