# Player animating the wrong direction once he is rotated

I have used the scripting root motion move the player when using an 'inplace' animation.

All works correctly until the players rotation is off 0,0,0. This is expected as the movement is along the transform.z axis but how can I account for the rotation in the script and apply it so the movement is correct in game?

The gorillacontroller script is the script we are trying to fix On playerGorilla. animator is on the playergorilla. The gorilla1 is the gameobject holding the mesh and the bones for the character.

I will also add the transforms are moving this was my silly mistake because I had tool handles in global instead of local.

This makes it even more confusing however because all tranform.z (blue axis) are facing the correct way for the animation to work but the animation is only ever playing in the original direction where the rotation is 0,0,0,0.

using UnityEngine;
using System.Collections;

[RequireComponent(typeof(Animator))]

public class RootMotionScript : MonoBehaviour {

void OnAnimatorMove()
{
Animator animator = GetComponent<Animator>();

if (animator)
{
Vector3 newPosition = transform.position;
newPosition.z += animator.GetFloat("Runspeed") * Time.deltaTime;
transform.position = newPosition;
}
}
}


• You mention below that this.transform's z direction is not rotating. Can you show us the hierarchy of your character so we can understand which part is rotating? Without this information, we have no idea where to get the correct movement direction from. – DMGregory Sep 16 '17 at 12:17
• added image to question. – ANDREW NOBLE Sep 16 '17 at 12:30
• We'll need more than that — which node(s) in that hierarchy are the ones that determine the player rotation? And where is this relative to the RootMotionScript's GameObject? Remember, the more clearly you can explain your situation, the more quickly you can get accurate, helpful answers. If we have to guess, we might guess wrong, and that's not helpful for anyone. – DMGregory Sep 16 '17 at 12:34
• Sorry, ill try to explain further. The gorillacontroller script is the script we are trying to fix On playerGorilla. animator is on the playergorilla. The gorilla1 is the gameobject holding the mesh and the bones for the character. – ANDREW NOBLE Sep 16 '17 at 12:47
• And which of those rotates, on which axis? Remember to put this information in your question via an edit, so users don't have to read a back-and-forth comment thread to understand what you need. – DMGregory Sep 16 '17 at 12:51

transform.position += transorm.forward * animator.GetFloat("Runspeed") * Time.deltaTime