- Home /
How can I play different animations depending on the direction my character is moving?
I currently have a Walking animation, 2 strafing animations, and the walk animation in reverse, but I am unsure how to make the game notice what direction I'm moving so that it can play the correct animation...
Walking = forward relative to the character Strafe Left = when I move to the left ETC.
I thought about just doing something like If(Input.GetButtonDown("w")) { animation.CrossFade"Default Walk" }
If(Input.GetButtonDown("a"))
{
animation.CrossFade"Left Strafe"
}
If(Input.GetButtonDown("d"))
{
animation.CrossFade"Right Strafe"
}
If(Input.GetButtonDown("s"))
{
animation["Default Walk"].speed = -1;
animation["walk"].time = animation["walk"].length;
animation.CrossFade("Default Walk",0.2);
}
But I was wondering is there a way to do something similar using the
If(Input.GetAxis("Horizontal")
{
Controller.Move((horizontal * (walkSpeed * Input.GetAxis("Horizontal"))) * Time.deltaTime);
}
If(Input.GetAxis("Vertical")
{
Controller.Move((vertical * (walkSpeed * Input.GetAxis("Vertical"))) * Time.deltaTime);
}
Answer by MarkD · Oct 12, 2013 at 09:50 AM
If you go to Windows inside unity and open the animator tab you can place multiple animations there and link them up to gether, so you can make smooth transitions between running forward and sideways. Simply place an Animation controller on your animated mesh's root bone. All you have to do then is write a script that detects the movement/direction by pressing buttons or realtime object position and link those variables to the variables insde your animation controller and you are done. I used it to create first person animations of the arm going from idle to holding stuff to throwing them.
Here is a tutorial from the staff itself, and it includes andvanced movement merging.
http://www.youtube.com/watch?v=Xx21y9eJq1U
it is fairly easy to get off with
Your answer
Follow this Question
Related Questions
Play animation for horizontal and vertical movement? 1 Answer
Get walk animation to play on horizontal and vertical axis presses. 2 Answers
Adapting Horizontal and Vertical movement to New Input System? 0 Answers
Make movement vertically,How to move Vertically? 1 Answer
what is difference of animation blend and animation crossfade? 0 Answers