- Home /
 
 
               Question by 
               Tactical_Programmer · Apr 18, 2020 at 11:47 PM · 
                animationanimator controllertopdowntop down shooterblendtree  
              
 
              Top-down character running animation based on character direction
I have a top-down character containing animations for running - running forwards, running backwards, strafe left and strafe right. I have all of the controls set up correctly based on joystick analog. I have set up a movement a 2d Freeform Cartesian blend tree that takes 2 inputs (InputX and InputZ, check the attached image). 
 Basically, the different animations play independent of where the character is looking.
How do I play the respective animation based on the direction, the character is facing at any moment?
Here is the movement/animation/rotation code:
 float x = joystick.Horizontal;
 float z = joystick.Vertical;
 
 //Movement
 Vector3 move = new Vector3(x, 0f, z);
 controller.Move(move* speed * Time.deltaTime);
 
 //Animations
 if(move != Vector3.zero)
 {
     anim.SetBool("isMoving", true);
     anim.SetFloat("InputX", x);
     anim.SetFloat("InputZ", z);
 }
 else
 {
     anim.SetBool("isMoving", false);
     anim.SetFloat("InputX", 0);
     anim.SetFloat("InputZ", 0);
 }
 
 //Rotation
 if (move != Vector3.zero && !playerWeapon.isAiming)
 {
     transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(move), rotateSpeed* Time.deltaTime);
 }
 
               
                 
                screenshot-20.png 
                (323.1 kB) 
               
 
              
               Comment
              
 
               
              Your answer