0 votes

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.

Navigation achieved!

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

Seems like we're stuck on a loop here...

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:

  1. Check if collision happens before moving (setting the test_only argument to true)
  2. If no collision happens, then move
  3. If collision happens, check if travel is larger than expected (larger than speed * delta, basically)
  4. If so, then move by using the value in remainder

Which works, but I still have two questions:

  1. 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?
  2. What exactly is the remaindervalue in KinematicCollision2D?
asked Feb 26 in Engine by brazmogu (64 points)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.