||Topic was automatically imported from the old Question2Answer platform.
||Published before Godot 3 was released.
I’m trying to set the position (to restore all elements back to their original position when the player dies) of a RigidBody2D with
RigidBody2D::set_pos but unfortunately, it don’t doesn’t change the position.
Is there any other way than
(Not an answer, since its a workaround), but if you make the level a scene, and when the player dies, delete and reinstance the level node, you won’t have to return everything to original values.
Bojidar Marinov | 2016-03-31 12:21
BTW, are you using
_process to update the positions?
Bojidar Marinov | 2016-03-31 12:23
I am using a save-anywhere mechanism, so I’m saving position and velocity of every object when saving the game. And no, I’m using a function which is called at the and of an animation played in an AnimationPlayer.
timoschwarzer | 2016-03-31 13:03
And btw doesn’t reinstancing the scene take loading time?
timoschwarzer | 2016-03-31 17:06
Please make sure to always call
set_global_pos inside a fixed process for physics objects, even when resetting them. See the docs.
This is a very common pitfall when dealing with Godot physics. It tricked me more than once.
var should_die = false
should_reset = false
# Will always work
# Might not work
# same goes if called from _process or input signal/_input callback
EDIT: The same apply for
set_angular_velocity. Setter and getters alike (you might get incorrect values from getters outside of the fixed process).
When I try to set the
rotation of a Rigidbody2D in the
_physics_process function in Godot 3.0, the body immediately jumps back to its previous position.
It only works in the
_integrate_forces function where I check if a
reset variable was set to
true and then I reset the body in this way:
state.transform = Transform2D(start_angle, start_pos)
state.linear_velocity = Vector2()
reset = false
How do i move the rigidbody to a position2d using this?
Yoseph | 2019-08-13 08:56