Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

I have this problem when animating my character?

Discussion in 'Animation' started by Johnscaban, Aug 18, 2021.

  1. Johnscaban

    Johnscaban

    Joined:
    May 9, 2020
    Posts:
    23
    I don't want people to think that I'm spamming, nobody answered me on the answers site, I am just stuck with this problem. Here is a (video) of my problem and here is my PlayerAnimator script:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.InputSystem;
    5.  
    6. public class PlayerAnimator : MonoBehaviour
    7. {
    8.     Animator animator;
    9.     PlayerInput playerInput;
    10.  
    11.     void Start()
    12.     {
    13.         animator = GetComponentInChildren<Animator>();
    14.         playerInput = GetComponent<PlayerInput>();
    15.     }
    16.  
    17.     void Update()
    18.     {
    19.         Vector2 movement = playerInput.actions["Move"].ReadValue<Vector2>();
    20.         Vector2 shooting = playerInput.actions["Shoot"].ReadValue<Vector2>();
    21.  
    22.         if (movement == Vector2.zero)
    23.         {
    24.             animator.SetFloat("inputX", 0f);
    25.             animator.SetFloat("inputZ", 0f);
    26.         }
    27.  
    28.         if (shooting == Vector2.zero)
    29.         {
    30.             animator.SetBool("isAttacking", false);
    31.         }
    32.  
    33.         if (movement != Vector2.zero)
    34.         {
    35.             animator.SetFloat("inputX", 0f);
    36.             animator.SetFloat("inputZ", 1f);
    37.         }
    38.  
    39.         if (shooting != Vector2.zero)
    40.         {
    41.             animator.SetBool("isAttacking", true);
    42.  
    43.             animator.SetFloat("inputX", movement.x);
    44.             animator.SetFloat("inputZ", movement.y);
    45.         }
    46.     }
    47. }