I'm making a SpriteKit game where two SpriteNodes are in a maze. That maze is represented as a grid. One sprite (A) travels faster than the other (B). Items randomly pop up, and the sprites have to collect them.

Pathfinding is easy (GKGridGraph is simple to use).

Here's the problem: At any given time, A and B could be on the same stretch of the maze. If A is behind B, I want A to be forced to go the same speed as B (cannot pass through or around). How can I accomplish this?

Thank you for your time!


A possible solution would be to simply make the faster player check for collision with the slower player when it moves.

You would first move the slower player, then try moving the faster one. If the faster player collides with the slower one (you should probably use dynamic/swept AABB for this), then you make it stop (or if you use swept aabb, you make it touch the slower player).

  • \$\begingroup\$ That helps! I was thinking that, but I wasn't sure if it would actually work. It helps that someone else suggested it as well. One problem is colliding on intersections. I suppose that would be an entirely different problem? Should I make each player check to see if someone is already on the intersection, and defer if so? \$\endgroup\$ – retrovius Dec 16 '17 at 19:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.