The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes


My RigidBody2D is not moving when I have not pressed a movement key for a second or 2. What could cause this problem? The RigidBody2D is in Character mode because I don't want it to rotate. The script has the following code:

extends RigidBody2D

const MAX_SPEED = 200

var motion = Vector2()

func _physics_process(delta):   
    if Input.is_action_pressed("ui_right"):
        motion.x = MAX_SPEED
    elif Input.is_action_pressed("ui_left"):
        motion.x = -MAX_SPEED
        motion.x = 0



in Engine by (21 points)

2 Answers

+1 vote
Best answer

For non-rotating rigid bodies you should generally use KinematicBody2D, which is essentially the same thing. Try switching the type and using moveandslide(motion). Is that the whole script? If not, can you paste the whole script?

by (247 points)
selected by

I chose to use RigidBodies as I want the player to be able to push certain objects, and I couldn't find a way to push other objects around when the player is a KinematicBody2D.
The script I posted was the full scripts. It's very basic, I know!

There's a way to make the player push stuff with physics, but chances are you want to have control over your pushing and make it work more like pushing blocks in ocarina of time. There are ways to do that that wouldn't need any of the extra properties of rigid body. But either way, the script doesn't even allow the player to move since you don't have anything like linear_velocity += motion. Motion is not a property of rigid body, so changing motion does not change player movement. And because of the way rigid body works, you have to change the built in linear_velocity to move it.

It probably didn't copy right... I have set_applied_force(motion) at the end of the script. But you're saying that I should use a KinematicBody?

You probably should use KinematicBody2D, and i would with the parameters you have given for the character. But if you want to use a rigid body, that's fine too. I tried using set_applied_force(motion) and i had no problems. Maybe it's something with your parameters? If you upload the project on github or dropbox and send me the link i can try to figure it out from there.

0 votes

If you can move the body, and then leave it alone for a few seconds, and then can't move it, it might be going to sleep. You can disable the 'Can Sleep' option, or just apply a force or movement and it should wake up again. More information is in the physics docs.

by (648 points)
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 Frequently asked questions and 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 [email protected] with your username.