Godot Version
V4.2.2
Question
How move/teleport RigidBody2D object?
I tried several solves:
1. just set position directly:
body.global_position = Vector2(x, y)
result: object come back
2. set position via PhysicsServer2D:
PhysicsServer2D.body_set_state(
get_rid(),
PhysicsServer2D.BODY_STATE_TRANSFORM,
Transform2D.IDENTITY.translated(Vector2(1.0, 2.0))
)
result: object come back
3. set state
in _integrate_forces
:
var _teleport_to: Vector2
var _is_teleport_needed: bool = false
func _integrate_forces(state):
if _is_teleport_needed:
_is_teleport_needed = false
state.transform.origin = _teleport_to
func teleport(pos: Vector2):
_teleport_to = pos
_is_teleport_needed = true
result: object come back
What am i doing wrong?