- Home /
 
 
               Question by 
               iamthecoolguy11 · Sep 20, 2021 at 01:24 AM · 
                c#speeddirection  
              
 
              How do I get a local movement direction
Im trying to get the moveing direction of a transform localy so that I can play animations, but when the character turns it plays the wrong animations.
Heres what I have.
  public Animator animator;
         // Start is called before the first frame update
         void Start()
         {
             InvokeRepeating("SlowUpdate", 0.05f, 0.05f);
         }
         Vector3 lastPos = new Vector3();
         void SlowUpdate()
         {
             Vector3 currentDirection = (transform.localPosition - lastPos).normalized;
             lastPos = transform.localPosition;
     
             animator.SetFloat("ForwardBackward", currentDirection.z);
             animator.SetFloat("LeftRight", currentDirection.x);
             //Debug.Log(currentDirection);
         }
 
              
               Comment
              
 
               
              Your answer
 
             Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
help with making enemy projectile fly at player at one speed 0 Answers
Continuous Adjustable Movement in 360 degrees 0 Answers
Multiple Cars not working 1 Answer