Play animation when two keys are pressed.
When my character walks diagonally I want my facing right or facing left animation to play based on the key combinations ( W and D, W and A, S and D, S and A).
I still want my character to move diagonally, but I don't want the animations to switch between up/right, etc. I'm unsure if I need a separate method to handle this, along with a separate animation controller. I know that I'll be using something similar to this for when the combinations of keys are pressed simultaneously, but the animations still switch between up/right.
if (Input.GetKey(KeyCode.W) && (Input.GetKey(KeyCode.D))
{
FacingDirection = Facing.RIGHT;
}
Here is my current player movement code:
private void TakeInput()
{
direction = Vector2.zero;
if(Input.GetKey(KeyCode.W))
{
direction += Vector2.up;
FacingDirection = Facing.UP;
}
if (Input.GetKey(KeyCode.A))
{
direction += Vector2.left;
FacingDirection = Facing.LEFT;
}
if (Input.GetKey(KeyCode.S))
{
direction += Vector2.down;
FacingDirection = Facing.DOWN;
}
if (Input.GetKey(KeyCode.D))
{
direction += Vector2.right;
FacingDirection = Facing.RIGHT;
}
Answer by ggamerz61 · Jan 04, 2021 at 01:55 AM
you might want to use blendtree https://www.youtube.com/watch?v=U0dlWhB_e0E
Your answer
![](https://koobas.hobune.stream/wayback/20220613022614im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Play animation once (when down key pressed) in c# 1 Answer
Selecting animation to play based on boolean 1 Answer
how to stop an animation at a specific frame on animator? 1 Answer
How to Play 2 Animation with Single Keypress ? I need Very Simple Script C# 0 Answers
How can I stop my character from walking during the attack animation? 1 Answer