Search Unity

Animation not playing

Discussion in 'Animation' started by TheDuke37, May 23, 2021.

  1. TheDuke37

    TheDuke37

    Joined:
    Feb 24, 2021
    Posts:
    1
    I've downloaded a character and some animations for a third-person game I'm making. This is the code for my character currently:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class PlayerControl : MonoBehaviour
    6. {
    7.     public CharacterController controller; //Links to the player's controller
    8.     public Transform cam;
    9.     public float speed; //Sets the player speed
    10.     public float turnSmoothTime = 0.1f;
    11.     float turnSmoothVelocity;
    12.     public Animator Anim;
    13.  
    14.  
    15.  
    16.     private Vector3 playerVelocity;
    17.  
    18.     void Start()
    19.     {
    20.         Anim = GetComponent<Animator>();
    21.     }
    22.  
    23.  
    24.     // Update is called once per frame
    25.     void Update()
    26.     {
    27.         float horizontal = Input.GetAxisRaw("Horizontal"); //Get A and D inputs
    28.         float vertical = Input.GetAxisRaw("Vertical"); //Get W and S inputs
    29.         Vector3 direction = new Vector3(horizontal, 0f, vertical); //Combine the inputs into a Vector3 variable named direction
    30.  
    31.         if (direction.magnitude >= 0.1f) //If the direction value is greater than 0.1 (the player should be moving)...
    32.         {
    33.             float targetAngle = Mathf.Atan2(direction.x, direction.z) * Mathf.Rad2Deg + cam.eulerAngles.y;
    34.             float angle = Mathf.SmoothDampAngle(transform.eulerAngles.y, targetAngle, ref turnSmoothVelocity, turnSmoothTime);
    35.             transform.rotation = Quaternion.Euler(0f, angle, 0f);
    36.  
    37.             Vector3 moveDirection = Quaternion.Euler(0f, targetAngle, 0f) * Vector3.forward;
    38.             controller.Move(moveDirection * speed * Time.deltaTime); //...move the player
    39.             Anim.SetBool("Moving", true);
    40.  
    41.         }
    42.         else
    43.         {
    44.             Anim.SetBool("Moving", false);
    45.         }
    46.  
    47.  
    48.     }
    49.  
    50. }
    51.  
    The strange thing is that in my animator tab, it shows that the animations are playing at the correct time. However in the game view, my character stays in their default pose as they move around. Does anyone know what I can do to fix this?
     
  2. Codebolt7

    Codebolt7

    Joined:
    Sep 30, 2019
    Posts:
    1