Difference in functionality when pressing different buttons

Hi everyone :slight_smile:

I am new to Unity and game developing, and while trying to create the jump function for the player, I found something that is not clear to me, and I would be glad for an explanation:

I am using Brackeys’ 2D Character Controller, and using the Move function in it with this code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMovement : MonoBehaviour
{
    public CharacterController2D controller;

    public float runSpeed = 40f;

    float hozrizontalMove = 0f;
    bool jump = false;

    void Update()
    {
        hozrizontalMove = Input.GetAxisRaw("Horizontal") * runSpeed;

        if (Input.GetAxisRaw("Vertical") > 0)
        {
            jump = true;
        }
    }

    private void FixedUpdate()
    {
        // Move the character
        controller.Move(hozrizontalMove * Time.fixedDeltaTime, crouch, jump);
        jump = false;
    }
}

I have noticed that when checking the press of the jump button instead of the vertical up button:

    void Update()
    {
        hozrizontalMove = Input.GetAxisRaw("Horizontal") * runSpeed;

        if (Input.GetButtonDown("Jump"))
        {
            jump = true;
        }
    }

the jump action in the game is noticeably lower.

In order to try to find the cause of the difference, I limited the jump functionality to occur only once:

public class PlayerMovement : MonoBehaviour
{
    public CharacterController2D controller;

    public float runSpeed = 40f;

    float hozrizontalMove = 0f;
    bool jump = false;

    bool already_jumped = false;

    void Update()
    {
        hozrizontalMove = Input.GetAxisRaw("Horizontal") * runSpeed;

        if (Input.GetAxisRaw("Vertical") > 0 && !already_jumped)
        {
            jump = true;
            already_jumped = true;
        }
    }

and found out that with this limitation the jump action with pressing the vertical up buttom is now the same as with the jump button, so I understand it’s probably something that relates to the Update and FixedUpdate functions together with the Implementation of the Move function, but I still don’t really understand the reason for it.

Input.GetAxisRaw(“Vertical”) will continuously send that command for every frame that you hold it.
This may cause it to input multiple times if you do not implement a minimum timer or a means of telling that you are already jumping.

Even with your “already_jumped” activated, it resets completely within two frames. Perhaps add a minimum timer to jump again, or check your jump height to see when to jump again.

Input.GetButtonDown(“Jump”) will only happen on a single frame until pressed again. Generally, you won’t have an issue with this giving multiple inputs, but it’s still probably a good idea to add a minimum timer (or any check to not allow multiple inputs too quickly) to this as well.