Jump button not working

Player isnt able to jump, it is running though, tried debug.log, on press of space(jump button) nothing is printing…and my space button is working properly, Im new to unity…pls help me find a remedy?

PFA Ss and working code

using System.Collections;

using System.Collections.Generic;

using Unity.VisualScripting;

using UnityEngine;

using UnityEngine.InputSystem;

public class PlayerMovement : MonoBehaviour

{

[SerializeField] float jumpSpeed = 5f;

[SerializeField] float runSpeed = 10f;

Vector2 moveInput;

Rigidbody2D myRigidbody;

Animator myAnimator;

void Start()

{

    myRigidbody= GetComponent<Rigidbody2D>();

    myAnimator= GetComponent<Animator>();

}

void Update()

{

    run();

    flipSprite();

}

void OnMove(InputValue value)

{

    moveInput=value.Get<Vector2>();

    Debug.Log(moveInput);

}

void onJump(InputValue value)

{

    if(value.isPressed)

    {

        // do stuff

        myRigidbody.velocity += new Vector2 (0f, jumpSpeed);

        Debug.Log("Jumping");

    }

}

void run()

{

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

    myRigidbody.velocity=playerVelocity;

    if(Mathf.Abs(myRigidbody.velocity.x)>Mathf.Epsilon)

        myAnimator.SetBool("isRunning",true);

    else

        myAnimator.SetBool("isRunning",false);

}

void flipSprite()

{

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

    if(playerHasHorizontalSpeed)

    {

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

    }

}

}

Hi,

Welcome to our community! :slight_smile:

C# is case-sensitive. Please check if all method names are spelt correctly. Since the jumping does not work, you could check the name of the corresponding method first. In the PlayerInput component, there is a list of methods. If you want to use one of those methods, compare your method name to the method in that list.

Did this help you fix the problem?


See also:

2 Likes

@Nina got it right. You can see all the messages the input will send in the inspector
image
Here you can see OnJump

You, however, wrote onJump - which is not the same. Changing it to OnJump should fix your problem

1 Like

Ohk thanks got it👍🏽

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

Privacy & Terms