Problem with moving RigidBody

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

I have just shifted from Godot 2d to 3d but I am unable to make nice movements.
I am using this code for my Rigidbody -

extends RigidBody

var jumpPower = 10

func _physics_process(delta):
	if Input.is_action_pressed("ui_left"):
		set_linear_velocity(Vector3(-1,0,0))
	if Input.is_action_pressed("ui_right"):
		set_linear_velocity(Vector3(1,0,0))
	if Input.is_action_just_pressed("ui_up"):
		set_linear_velocity(Vector3(0,jumpPower,0))

when the body is on ground it works fine
but when I move the body after it jumps and is in air it is flying and when i again leave the arrow keys only after that gravity effects it.

:bust_in_silhouette: Reply From: AndyCampbell

Not sure, but I assume when you set linear_velocity you are overriding the movement calculated by the physics engine. Specifically you are setting the linear_velocity y component to 0 which will stop any vertical movement from gravity.

It will probably be easiest to use a KinematicBody for your player, and manage the effect of gravity yourself. That will still allow you to use the collision engine etc. Or you can try to manage movement by interacting with the physics engine (eg instead of setting linear_velocity directly, you can apply_impulse() or add_force(), but that will probably more complicated