Move/teleport RigidBody2D

Godot Version



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:

    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?

I’m sorry, i’m stupid, i have a next nodes structure:

And try moving leg_l and leg_r, if remove joints before that, then moving is ok for anyway.

I just thought that if the joint is a child, then its anchor will move with it. Apparently, this is not the case.

At the moment, I’m thinking of removing the joints before moving and inserting them again after.

It’s a little weird, but I’m willing to accept it.