Hi, so I made my character and a few animations to go along with it using Adobe Fuse and Mixamo. I’m having a few problems and after hours of searching for resolutions, I’m starting to go bananas! (literally)
Ok so enough sob story, let me tell you about my setup. I have an Animator Controller(AC) attached to my character GameObject and inside the AC there are two animations, an Idle which transitions from the entry, and a Walking animation. The idle seems to be working fine, but the Walking is where I get my problems. I want the player to be able to press the arrow keys and for the Walking animation to play while the key is being held down and once its released I want the animation to switch back to Idle. I currently have a script that controls my character movement but when I press the keys the Walking animation only play once, not repeatedly and it doesn’t go back to Idle.
Here is my c# script that’s attached to my character:
public class Harpermovement : MonoBehaviour {
public float speed = 2.0f;
public Animator anim;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
anim = GetComponent<Animator>();
if (Input.GetKey(KeyCode.RightArrow))
{
anim.Play("Walking");
transform.position += Vector3.right * speed * Time.deltaTime;
}
if (Input.GetKey(KeyCode.LeftArrow))
{
anim.Play("Walking");
transform.position += Vector3.left * speed * Time.deltaTime;
}
if (Input.GetKey(KeyCode.UpArrow))
{
anim.Play("Walking");
transform.position += Vector3.forward * speed * Time.deltaTime;
}
if (Input.GetKey(KeyCode.DownArrow))
{
anim.Play("Walking");
transform.position += Vector3.back * speed * Time.deltaTime;
}
}
}
Also, if anyone knows how to switch the position my character is facing when I press the left and right arrow keys to walk that would be awesome. Currently when I walk her to the side her feet are still walking forward but she’s moving sideways