- Home /
When i make my character animated, he can only move up, down left and right (2D) (JS)
Without animations, my character can move diagonally, but as soon as i add animations you can only move up, down, left and right. Here's my code:
public var speed: float;
var anim = GetComponent.<Animator>();
function LateUpdate () {
if (Input.GetKey(KeyCode.W)) {
transform.Translate(Vector2.up * speed);
anim.Play("WalkUp");
}
else if (Input.GetKey(KeyCode.S)) {
transform.Translate(-Vector2.up * speed);
anim.Play("WalkDown");
}
else if (Input.GetKey(KeyCode.D)) {
transform.Translate(Vector2.right * speed);
anim.Play("WalkRight");
}
else if (Input.GetKey(KeyCode.A)) {
transform.Translate(-Vector2.right * speed);
anim.Play("WalkLeft");
} else {
anim.Play("Idle");
}
}
Comment
Your answer
Follow this Question
Related Questions
SpriteManager 2 1 Answer
Sprite animation 2 Answers
Animator warning in editor, animation is preventing script from working 1 Answer
2D Sprite animation - How do I jump to the next frame? 0 Answers