So, I'm making this isometric RTS-y game and I'm implementing basic navigation by means of potential fields so my actors automatically curve around obstacles towards their target. It works nicely by calculating the velocity of the actor by adding up all the "repulsion" vectors from the obstacles and then using move_and_collide
to figure out any collision that might happen on the way.

Neat. But it wasn't always like that...

This weird thing was happening where if the actor was moving close to the tangent of the osbtacle (they both have flattened circles as collision shapes) the actor would start circling around, then suddenly jump back and then continue again, getting stuck forever...
I debugged the code and found that the KinematicCollision2D
object move_and_collide
was giving me had a weird value for travel
which was completely against the direction of the vector the obejct was supposed to be moving towards. Now, as you've seen in the first GIF, I have fixed it, and the fix was simple:
- Check if collision happens before moving (setting the
test_only
argument to true)
- If no collision happens, then move
- If collision happens, check if
travel
is larger than expected (larger than speed * delta
, basically)
- If so, then move by using the value in
remainder
Which works, but I still have two questions:
- Why is the
move_and_collide
(or move_and_slide
) method sending my actor way far from where it should be moving to in the next step?
- What exactly is the
remainder
value in KinematicCollision2D?