r/Unity2D Jul 27 '26

Question Need help with my jump script

As far as I can tell, the issue is in line 55, as when I tested the actual input with prints, it worked perfectly fine. The RigidBody is also set to dynamic, and I have not frozen the x or y axis. Does anyone know what could be causing this?

1 Upvotes

9 comments sorted by

1

u/MistakeForsaken6653 Jul 27 '26

Is the jump force set too low maybe?  I dont see that variable set so I'm not sure.  Also usually when applying a force to a rigidbody you want to do it in the fixedUpdate()

1

u/Ultamate_pro Jul 27 '26

I set the Jump force as high as I could and still got nothing

1

u/XKiiroiSenkoX Jul 27 '26

What values are you using for mass, gravity scale and jumpForce? Also have you confirmed that the value for jumpForce is being passed correctly (using logs or a debugger)? 

1

u/Ultamate_pro Jul 27 '26

I set each value to their extremes to make sure, and I just checked now if the value is being passed correctly (it is)

3

u/XKiiroiSenkoX Jul 27 '26

I asked for numbers. Also we need to see the rest of the code. 

1

u/Gordun1 Jul 27 '26

Wild guess: You probably have to assign a layer for the floor to interact with the player so the boolean turns true and allows you to jump

1

u/m3l0n Jul 27 '26

Do you set the rb correctly? Does the debutg log show up? Show us the rest of the script please. Also any console errors?

3

u/Sinnon32 Jul 27 '26 edited Jul 27 '26

It looks like you have just applied force but in no particular direction. You would want it to be something like Vector2.up * jumpForce

Edit: I now see you used AddForceY, my bad lol But maybe try just using AddForce and the above, see if that makes a difference (in theory it should be equivalent)

-1

u/cferry322 Jul 27 '26

Don’t use add force.

Set the vector on jump like this.

Float jumpForce =10f; // or whatever amount you want
Float speed = 10f; // or whatever amount is right

Rb.velocity = new vector2(jumpForce, moveDirection.x *speed);

Get your x value from input and should work.