Problems changing Position

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

Hey, I’m having trouble moving an object (a RigidBody2D) using the Position variable. When I run the code, the position of the object changes for a moment, but then returns to its previous position.

The object is a scene instantiated in another one, a RigidBody2D (Character), which has as children a CollisionShape2D and a Sprite. I have tried with a similar object and everything goes well, but this object appears in the indicated position for a moment, and then it returns to its original position. There is no code that is causing this.

:bust_in_silhouette: Reply From: kidscancode

That’s because, as indicated in the docs, you cannot change a rigid body’s position directly.

A rigid body is controlled by the physics engine, which calculates the forces on it, any collisions, and determines its velocity and position. This is the point of using a rigid body, so that you don’t have to do all those calculations yourself.

If you’re trying to control its movement, then you have to apply forces.

If you want to do a one-time change, like a teleport, then you can do that by directly altering the physics state in _integrate_forces().

For more information, see the RigidBody2D docs at: