My jump button stopped working

Today I open my project e the jump input wasn’t working anymore. I don’t know if I
accidentally change something or not. I printed the code and one screen of my Unity project trying to show my project settings. I already check the Input System too, and I can’t see what’s wrong. Anyone have some ideia of what is going on?




Hi Terezu,

Please note, it’s better to copy/paste your code and apply the code fencing characters, rather than using screenshots. Screenshots are ideal for displaying specific details from within a game engine editor or even error messages, but for code, they tend to be less readable, especially on mobile devices which can require extensive zooming and scrolling.

You also prevent those that may offer to help you the ability to copy/paste part of your code back to you with suggestions and/or corrections, meaning that they would need to type a potentially lengthy response. You will often find that people are more likely to respond to your questions if you make it as easy as possible for them to do so.

Is the player able to run? Or is the problem limited to the jumping skill? If the player does not move at all, is there an EventSystem in your Hierarchy? If not, add one.

Hope this helps. :slight_smile:


See also:

Hi Nina,

Thanks for replying me. The player is able to run. Was able to jump before yesterday. I guess I made something in Unity that’s prevent him to jump now. Here’s my code:

using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.InputSystem;

public class PlayerMovement : MonoBehaviour
{
[SerializeField] float runSpeed = 5f;
[SerializeField] float jumpSpeed = 5f;

Vector2 moveInput;
Rigidbody2D myRigidbody;
Animator myAnimator;
CapsuleCollider2D myCapsuleCollider;


void Start()
{
    myRigidbody = GetComponent<Rigidbody2D>();
    myAnimator = GetComponent<Animator>();
    myCapsuleCollider = GetComponent<CapsuleCollider2D>();
}

void Update()
{
    Run();
    FlipSprite();
}

void OnMove(InputValue value)
{
    moveInput = value.Get<Vector2>();
    Debug.Log(moveInput);
}

void OnJump(InputValue value)
{
    if (!myCapsuleCollider.IsTouchingLayers(LayerMask.GetMask("Ground"))) { return; }
    if (value.isPressed)
    {
        myRigidbody.velocity += new Vector2(0f, jumpSpeed);
    }
}

void Run()
{
    Vector2 playerVelocity = new Vector2(moveInput.x * runSpeed, myRigidbody.velocity.y);
    myRigidbody.velocity = playerVelocity;

    bool playerHasHorizontalSpeed = Mathf.Abs(myRigidbody.velocity.x) > Mathf.Epsilon;
    myAnimator.SetBool("isRunning", playerHasHorizontalSpeed);
}

void FlipSprite()
{
    bool playerHasHorizontalSpeed = Mathf.Abs(myRigidbody.velocity.x) > Mathf.Epsilon;

    if (playerHasHorizontalSpeed)
    {
        transform.localScale = new Vector2(Mathf.Sign(myRigidbody.velocity.x), 1f);
    }
}

}

I also tried to add an Event System to my Hierarchy, has you suggested, but nothing changes. Maybe some settings on Unity that I accidently had change?

Thank you. That’s much better. :slight_smile:

Maybe the player isn’t touching the ‘Ground’ layer for some reason. Or value.isPressed is false all the time. This is impossible to tell just by looking at the code, so please try to analyse the situation with Debug.Log.

I figured out what was happen. I forgot to turn on my ground layer. Now it’s working!

Thanks for your time and help, Nina. I will continue with my studies.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms