0 votes

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
else:
    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
asked Aug 14 in Engine by StalinIsMyFriend (14 points)

I don't know how I can help you, but I might be able to improve your code a little. ;)

I would change this:

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

To this:

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

Hi,
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 https://github.com/godotengine/godot-demo-projects/tree/master/3d/kinematic_character

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

Hope it helps.

Please log in or register to answer this question.

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.