#Is there a reason why my attack animation plays twice?

1 messages · Page 1 of 1 (latest)

atomic frigate
#

Here is a video demonstration of my code. I am creating a melee combat system with a 4 hit combo. What is the possble reason for my animation playing twice before returning to the idle animation?

Here is my Player Combat script so far:

{

    public bool meleeButtonPressed;
    public bool canReceiveInput;
    public PlayerMovement playerMovement;
    private Animator playerAnimator1;
    
    private int buttonClick;

    public bool isCombatMode;
    /// <summary>
    /// This function should check when the player presses the attack button. 
    /// When the player presses it continuosly the plyer will cycle through different attack combo animations
    /// </summary>

    private void Start()
    {
        playerAnimator1 = GameObject.Find("Player 1").GetComponent<Animator>();
        canReceiveInput = true;
    }

    public void CombatInputRecieved()
    {
        if (Input.GetKey(playerMovement.meleeButton) && canReceiveInput)
        {
            isCombatMode = true;
            canReceiveInput = false;
            meleeButtonPressed = true;
        }

        if (meleeButtonPressed)
        {
            playerAnimator1.SetBool("Combat Mode", isCombatMode);
            playerAnimator1.SetTrigger("Melee Attack");
        }
    }

    private void FixedUpdate()
    {
        CombatInputRecieved();
    }
} ```
hallow ice
#
  1. Input handling in FixedUpdate - not good
  2. Using Input.GetKey and checking it every (fixed) frame here
  3. The if (meleeButtonPressed) thing will run every (fixed) frame until it gets set to false
#

I also don't see anywhere that you set meleeButtonPressed to false

dark otter
#

you'd probably want to use GetKeyDown here wouldn't you

#

(and that wouldn't work properly in FixedUpdate)

atomic frigate
dark otter
#

analog inputs will be updated every frame

#

for continuous digital updates technically it can work, but it won't be up-to-date

atomic frigate