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

Question FPS hands animation problem

Discussion in 'Animation' started by fierarux777, Aug 27, 2021.

  1. fierarux777

    fierarux777

    Joined:
    Feb 11, 2019
    Posts:
    35
    So I made a few animations for some fps hands created in blender. I made separate animations for shooting and ADS(aim down sight) shooting, but for some reason unknown to me, when I am aiming and then pressing the fire button, the ADS shooting animation doesn't happen. Can someone explain to me why?

    Here is a pic of the animation controller:

    upload_2021-8-28_0-25-40.png

    Here is the code for the animation controller:

    Code (CSharp):
    1.  
    2.  
    3. using System.Collections;
    4. using System.Collections.Generic;
    5. using UnityEngine;
    6.  
    7. public class animatin_play : MonoBehaviour
    8. {
    9.     private Animator anim;
    10.     public AudioSource boom;
    11.     public Camera eyes;
    12.  
    13.     void Start()
    14.     {
    15.         anim = GetComponent<Animator>();
    16.         boom = GetComponent<AudioSource>();
    17.     }
    18.  
    19.     // Update is called once per frame
    20.     void Update()
    21.     {
    22.         if(Input.GetKeyDown(KeyCode.Mouse0) && !Input.GetKey(KeyCode.Mouse1))
    23.         {
    24.             anim.Play("Shoot");
    25.             boom.Play();
    26.         }
    27.  
    28.         if(Input.GetKeyDown(KeyCode.R))
    29.         {
    30.             anim.Play("Reload");
    31.         }
    32.  
    33.         if(Input.GetKey(KeyCode.Mouse1))
    34.         {
    35.             anim.SetBool("isADS", true);
    36.             anim.Play("ADS_on");
    37.             eyes.fieldOfView = 15;
    38.         }
    39.         else
    40.         if(Input.GetKeyUp(KeyCode.Mouse1))
    41.         {
    42.             anim.SetBool("isADS", false);
    43.             eyes.fieldOfView = 45;
    44.         }
    45.  
    46.         if(Input.GetKey(KeyCode.Mouse1) && Input.GetKeyDown(KeyCode.Mouse0))
    47.         {
    48.             anim.SetTrigger("ADS_shoot");
    49.             boom.Play();
    50.         }
    51.     }
    52. }
    53.  
     
  2. sstrong

    sstrong

    Joined:
    Oct 16, 2013
    Posts:
    2,229
    Add some Debug.Log(..)s in your code to first make sure it is doing what you want. Then in play mode (game view not maximised) click on the animator in the Hierarchy and watch what happens to the parameters while also seeing which states are being played in the anim controller window.

    That will help you debug your animation controller.
     
    fierarux777 likes this.