Topic was automatically imported from the old Question2Answer platform.
Asked By
lostact
in godot 2 it was possible to change position of a rigidbody2d inside other nodes script using RigidBody2D.set_pos() but in godot 3 set_pos() not works because of interferes with the physics simulation…
the other way is changing Transform2D.origin using state.set_transform(Transform2D) inside _integrate_forces(state) and the problem is you can’t get a rigidbody’s state outside of _integrate_forces(state). is there any function to get state of other objects? or is it possible to change a rigidbody’s position without using state.set_transform()?
You’re confusing separate issues. set_pos() was not removed, it was changed to use the position member variable. All Node2D-derived nodes can now use
position = Vector2(x, y)
to set position.
RigidBody2D behavior has not changed. It was never a good idea to set the position directly.
Why not send a signal and/or call a function on the target body to tell it you want it to teleport, and then it does so in its integrate_forces() call?
i know pos changed to position and i used rigidbody.position=vector2(x,y) but it changes the position for only one frame and then it returns. i tried changing a variable of the target body as a signal and it worked fine, thank you.
lostact | 2018-02-01 15:19
Thanks for mentioning this issue.
I had the very same situation:
“i used rigidbody.position=vector2(x,y) but it changes the position for only one frame and then it returns.”
I simply created a new instance from my object to the new position.
I am Noob.
DavidPeterWorks | 2018-04-23 17:24
That’s because as the RigidBody documentation explicitly says, you can’t set its position directly and expect it to work.
Thanks. Is there any best practice to move the RigidBody2d to a specific position within 1 frame.? In short:
I am looking for a way to Teleport rigidbody2d.
To safely and reliably teleport a rigid body, you have to use the Physics2DDirectBodyState. I have an example with explanation here: Godot 3.0: Rigid Bodies · KCC Blog