Having trouble moving KinematicBody2D objects in code without them colliding with their past positions.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By EPriest

I’m having trouble understanding how collisions work regarding KinematicBody2D objects and the move_and_collide or move_and_slide functions.

I want to change the positions of these objects and then move them in the same frame, but they are colliding with their past positions. The collision code isn’t fully registering the position change. For example, the following code executed in _physics_process causes a collision.

$CollisionShape2D.disabled = true
var old_position = position
position = swap_to.position
swap_to.position = old_position
$CollisionShape2D.disabled = false
var collide = move_and_collide(Vector2.ZERO)
if collide:

Is there a better way to change the positions of KinematicBody2D objects and then call move_and_collide() without these objects registering collisions?

:bust_in_silhouette: Reply From: FuLeZi

I think disabling the shape before changing the body’s position has no effect.
Plus I think the move operation does not update the shapes right away.
You can try by excluding the Kinematic both together: