I got a free asset from the Unity Store to start experimenting with animations. The only issue with it is that I need to bind each of the different states to a WASD/space input. I tried to copy the animation from a cinemachine demo(video: https://www.youtube.com/watch?v=537B1kJp9YQ&t=237s) but didn’t have any luck. The character has an idle, walk, run, 2 attack states, and a death state. What do I need to change?
Here is my player controller code:
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public float jumpForce = 7.51f;
public bool isOnGround = true;
private Rigidbody playerRb;
private Animator playerAnim;
public float horizontalInput;
public float forwardInput;
public float speed = .02f;
public float turnSpeed = 10;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
playerRb = GetComponent<Rigidbody>();
playerAnim = GetComponent<Animator>();
}
public bool shouldMove;
public bool isMoving;
// Update is called once per frame
void Update()
{
float xDirection = Input.GetAxis("Horizontal");
float zDirection = Input.GetAxis("Vertical");
Vector3 moveDirection = new
Vector3(xDirection, 0.0f, zDirection);
transform.position += moveDirection * speed;
if (Input.GetKeyDown(KeyCode.Space) && isOnGround)
{
playerRb.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
isOnGround = false;
}
playerAnim.SetBool("IsMoving", shouldMove);
}
public void OnCollisionEnter(Collision collision)
{
isOnGround = true;
}
}