Rigidbody position setting glitch

Godot Version

4.4

Question

The player is a rigid body 2d. When they hit the killzone area, they are supposed to be teleported back to their last checkpoint, but for some reason it puts the player back where they were when they entered the killzone, then teleporting back to the checkpoint, then back to the killzone, etc.


In the video it looks like it only happens once, but it happened like every frame.

Heres the code for the killzone

func _on_ball_collision_area_entered(area: Area2D) -> void:
	if area.name == "zonekill":
		position = GameManager.spawn_point #this is the position of the players last checkpoint.

You can’t teleport (aka change the position) of a RigidBody2D like that because the physics system won’t be synced and it will cause issues.

You’ll need to do it in RigidBody2D._integrate_forces() and modify the state.transform.origin accordingly. You can check this answer How can I change a node's position during physics interpolation without fast moving effect? - #2 by mrcdk as to how to do it