0 votes

my code

func physicsprocess(delta):
velocity.y += gravity * delta
if Input.isactionpressed("uiright"):
motion.x = 400
elif Input.is
motion.x = -400
elif Input.isactionpressed("jump"):
motion.y = -800
motion.x = 0
motion.y = 0
gravity = 400

asked Jul 29 in Projects by fish (16 points)

1 Answer

+2 votes
Best answer

You could try with:

elif Input.is_action_pressed("jump") and is_on_floor():
    motion.y = -800

Also, note that you should update the motion using move_and_slide so the gravity doesnt add while on floor, like this:

motion = move_and_slide(motion, Vector2.UP)

I also added the second parameter as i assume you are making a side scroller from your controlls. The function needs that parameter to know where is the floor.

answered Jul 29 by p7f (3,284 points)
selected Jul 31 by fish

thank you, i have been stuck on this for hours

No problem. If it worked, you may select the answer so others see its solved!

I've been trying to get is_on_floor() to work for so long! Thank you!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.