0 votes

the is_on_floor() is not working properley.
when I try to jump :
if Input.is_action_just_pressed("jump") and is_on_floor(): velocity.y = jump_force
is not working but this will be work? :
if Input.is_action_just_pressed("jump"): velocity.y = jump_force


The code:
extends KinematicBody2D export var gravity = 20; export var speed = 10; export var jump_force = -1000; var velocity = Vector2(0,0) func _physics_process(delta): if Input.is_action_pressed("ui_right"): velocity.x = speed * 100 elif Input.is_action_pressed("ui_left"): velocity.x = -speed * 20 velocity.y = velocity.y + gravity if Input.is_action_just_pressed("jump") and is_on_floor(): velocity.y = jump_force velocity = move_and_slide(velocity) velocity.x = lerp(velocity.x,0,0.2)

in Engine by (12 points)

Please post your code properly, it is impossible to read like this.

When posting your question, there is a "Code Sample" button, it looks like {}.

3 Answers

0 votes

I have the exact same issue. Following for updates!!!

Did you have any luck with:

if Input.is_action_just_pressed("jump"): velocity.y = jump_force


Stian Skjelbred,

by (14 points)
+1 vote

You need to specify the up_direction in move_and_slide, so it knows where the floor is.


velocity = move_and_slide(velocity, Vector2.UP)
by (1,482 points)
0 votes

if anyone still having these problems, make sure you set your collision layers properly and not assign different bodies with the same layers. for example: assign anything thats ground as Layer 1 and the player body as Layer 2. And only assign the Layer 1 to interact with Layer 2 and vice versa.

Edit: it has produce problems on my end in the long run. not recommended

by (18 points)
edited by
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.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.