Currently, I have enabled physics interpolation. When I directly change the position, the object flickers between the two points, as if it were moving at high speed rather than teleporting instantly.
According to the doc, I attempted to use reset_physics_interpolation() to resolve this issue, but calling this function had no effect.
What are you trying to reset? If it’s a rigid body then the physics engine will take precedence once you teleport it so it won’t work. You need to do it inside the RigidBody2D._integrate_forces() function and modify the state.transform.origin instead.
extends RigidBody2D
@onready var reset_pos = global_position
var reset = false
func _integrate_forces(state: PhysicsDirectBodyState2D) -> void:
if reset:
state.transform.origin = reset_pos
# Call reset_physics_interpolation() at the end of the frame once the physics engine has been updated
reset_physics_interpolation.call_deferred()
reset = false
func _on_area_2d_body_entered(body: Node2D) -> void:
if body == self:
reset = true
Result:
Left is being interpolated, right is not. I lowered the physics ticks per second to 20 in the example.