Search Unity

Archer Holding Aiming animation

Discussion in 'Animation' started by Reardon_C, Apr 28, 2021.

  1. Reardon_C

    Reardon_C

    Joined:
    Jun 18, 2020
    Posts:
    1
    Hello,

    I am trying to animate an archer character in 3d, so that he draws an arrow, pulls the bow string, holds the bow and arrow in the "ready to fire" position, and finally fires the arrow.

    I am struggling with the holding the bow in the ready to fire position. It keeps looping through the whole animation of pulling out an arrow, drawing the bow, and then firing. I have my code set up to draw the arrow on left mouse button held down, checking a bool to see if the character is aiming, and then playing the fire animation on left mouse button release. (I am pasting the code for that below)

    void DrawArrow()
    {
    if (Input.GetButton("Fire1"))
    {
    m_Animator.SetTrigger("DrawArrow");
    isAiming = true;
    if (isAiming)
    {
    m_Animator.SetBool("pullString", true);
    }
    }

    }

    void FireAndRecoil()
    {
    if (Input.GetButtonUp("Fire1"))
    {
    m_Animator.SetTrigger("FireAndRecoil");
    isAiming = false;
    }
    }
    }

    I am feeling like I could be just missing a setting in the animator that would be telling it to hold the pose where the archer has the bow completely drawn back and ready to fire, but am at a loss. Does anyone know how to keep the character in the bow drawn animation until it is told to fire? Any help is greatly appreciated, and thanks in advance.
     
  2. Yandalf

    Yandalf

    Joined:
    Feb 11, 2014
    Posts:
    491
    I don't know how your Animator is set up, but I'm having an idea what might be going wrong.
    You're calling the SetTrigger function for what I assume is the start of your drawing process each frame during a mousehold. Input.GetButton will keep returning true every frame when you click or hold an input key. If you want to have that return true only i the frame where you begin clicking, you need to use Input.GetButtonDown.
    Depending on how you enter the DrawArrow animation (my guess is that you enter it from Any State using the DrawArrow trigger), then you're continuously re-triggering the animation right now.

    I'm not sure if the pullString bool is necessary really. You could set up your animator to automatically go from the DrawArrow animation to a Hold/Aim animation by just making the transition happen at the end of the former's state without any parameter requirements, and then keep it within the aim state until FireAndRecoil is triggered.