The animator and animation editor is really confusing so I'm trying to do this with scripting. This works pretty well except for when I'm holding L & J at the Same time... For example, if I have an animation for walking left, up, right, and down. How would I animate moving diagonally? Up and right at the same time? etc. (I'm using IJKL instead of WASD) Code (CSharp): void Update () { if (Input.GetKeyDown (KeyCode.L) && !WalkRight.activeInHierarchy) { WalkRight.SetActive (true); GetComponent<SpriteRenderer> ().enabled = false; } if (Input.GetKeyUp (KeyCode.L) && WalkRight.activeInHierarchy) { WalkRight.SetActive (false); GetComponent<SpriteRenderer> ().enabled = true; } if (Input.GetKeyDown (KeyCode.J) && !WalkLeft.activeInHierarchy) { WalkLeft.SetActive (true); GetComponent<SpriteRenderer> ().enabled = false; } if (Input.GetKeyUp (KeyCode.J) && WalkLeft.activeInHierarchy) { WalkLeft.SetActive (false); GetComponent<SpriteRenderer> ().enabled = true; }
Do what other Game Developers have done in the past. decide on a priority and stick to it. Take virtually any 2.5 game as an example. you could make animations that shows the sprite moving in 8 directions, like Doom II. or in 4 directions like in Paper Mario. and in those examples when an actor is moving at an angle thats between two animations, they always make one of the animations a priority. and to handle conflicting controls. have the inputs add up a vector. if that vector is zero (which will happen for opposing inputs) then you don't update the animation, as if the player isn't pressing any buttons. so holding the "J" and the "K" keys will add up a (-1,-1) Vector2 so the character does a downleft animation (if thats inbetween 2 animations I would favor left). if the keys held down are "J","K", and "L" the vector adds up to (0,-1) since J and L cancel out and the character only moves down.