My Jump Script Won't Work!

I’m having trouble with my jump script, I was using a video tutorial to make a 2D Metroidvania but the script in the video isn’t working, I’m using a newer version of unity than in the video so I’m not sure if that’s the problem. Also the only thing my visual studio is set to use is unity code, so maybe that’s a problem too? Here’s the link to the video and website:https://blog.terresquall.com/2023/04/creating-a-metroidvania-like-hollow-knight-part-1/

And here’s my code: (Sorry I don’t know how to show it properly so i’ll just copy and paste)

using UnityEngine;

public class PlayerControl : MonoBehaviour
{
    [Header("Horizontal Movement Settings:")]

    private Rigidbody2D rb;

    [SerializeField] private float walkSpeed = 1;

    private float xAxis;

    [SerializeField] private float jumpForce = 45;


    // Start is called once before the first execution of Update after the MonoBehaviour is created
    void Start()
    {
        rb = GetComponent<Rigidbody2D>();   
    }

    // Update is called once per frame
    void Update()
    {
        GetInputs();
        Move();
    }
    void GetInputs()
    {
        xAxis = Input.GetAxisRaw("Horizontal");
    }

    private void Move()
    {
        rb.linearVelocity = new Vector2(walkSpeed * xAxis, rb.linearVelocity.y);
    }
}

I don’t see any code that pertains to jumping in the code you posted?

Huh I thought the part below did that

[SerializeField] private float jumpForce = 45;

That’s only a serialized field. Ergo, a value you can modify in the inspector. You still need to write code that actually does something with the value.

You need to continue following the tutorial.

It worked in the tutorial though? I’m very confused…
The part where they write the script is at 6:23

The video is just showing an example of how the jump should behave at that timestamp, not what the code they’ve written is doing.

Please continue following the tutorial.

1 Like

Thank you so much it worked!!! :grin:

1 Like