0 votes

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.

in Engine by (15 points)

1 Answer

+1 vote
Best answer

Not sure, but I assume when you set linearvelocity you are overriding the movement calculated by the physics engine. Specifically you are setting the linearvelocity 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 linearvelocity directly, you can applyimpulse() or add_force(), but that will probably more complicated

by (484 points)
selected 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.

Categories