KinematicBody player stops moving after jumping

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By StalinIsMyFriend

So, It’s difficult to explain it. I have a KinematicBody player and for some reason after you jump, you can’t move on x and z axis for one moment. Please explain to me what i did wrong:

func _physics_process(delta):
if is_on_floor() == false:
	y_velocity -= 0.4
	y_velocity = 0
if is_on_floor() && Input.is_action_pressed("ui_select"):
	y_velocity = jump_height
if Input.is_action_pressed("ui_up"):
	velocity.z += -get_global_transform().basis.z.z
	velocity.x += -get_global_transform().basis.z.x
if Input.is_action_pressed("ui_down"):
	velocity.z += get_global_transform().basis.z.z
	velocity.x += get_global_transform().basis.z.x
if Input.is_action_pressed("ui_left"):
	velocity.z += -get_global_transform().basis.x.z
	velocity.x += -get_global_transform().basis.x.x 
if Input.is_action_pressed("ui_right"):
	velocity.z += get_global_transform().basis.x.z
	velocity.x += get_global_transform().basis.x.x
velocity = velocity.normalized() * speed
velocity.y = y_velocity
velocity = move_and_slide(velocity, Vector3(0, 1, 0), false, 4)
velocity.x = 0
velocity.z = 0

I don’t know how I can help you, but I might be able to improve your code a little. :wink:

I would change this:

if is_on_floor() == false:
    y_velocity -= 0.4
    y_velocity = 0

To this:

if is_on_floor():
   y_velocity = 0
   y_velocity -= 0.4

Ertain | 2019-08-14 21:01

What type of game is the player for? (Third person with camera following, isometric fixed camera, etc)
What type of movement is the player meant to perform (eg camera always faces forward and player doesn’t face the camera, or player faces direction of movement, so faces the camera if “back” is pressed)?

The godot demo templates include some basic third person movement examples, which can be used as a base for more complex movements).

The third person demo template can be found at

When you say you can’t move after jumping, do you mean while in the air, or when you’ve landed?

Hope it helps.

DamonR | 2019-08-14 21:44