gdscript set position of rb2d not works, looks like rb rewrite position
- User
gdscript set position of rb2d not works, looks like rb rewrite position
- Assistant
If setting the position of an RigidBody2D node in Godot's GDScript does not work as expected, it could be because the physics engine is overriding the position based on its calculations. To ensure that the position is set correctly, you can try disabling the physics for a brief moment, setting the position, and then re-enabling the physics.
Here's an example of how you can do this in GDScript:
# Disable physics temporarily $RigidBody2D.mode = RigidBody2D.MODE_STATIC # Set the new position $RigidBody2D.position = Vector2(100, 100) # Re-enable physics $RigidBody2D.mode = RigidBody2D.MODE_RIGIDBy temporarily setting the RigidBody2D node to
MODE_STATIC, you can update the position without interference from the physics engine. Just remember to switch it back toMODE_RIGIDonce you're done.Another option is to use a KinematicBody2D node instead, which allows you to directly control the position without interference from the physics engine.