I’m testing out a mechanic where multiple moving objects are going to the same target. I’m trying to have the objects separate and pause whenever a collision is detected (like lining up for a queue).
It seems to work well for the first collision, and then they just start overlapping and blinking without pausing.
In the scene, the blue balls are the pathfinding objects, the blocks are pathfinding obstacles, and the target is the destination
I have tried using other behaviors to separate the balls, but none of them seem to work so far
- setting the balls as pathfinding obstacles as well → the balls just don’t move at all
- setting the balls as physics objects with 0 gravity → the balls stop moving
- Removing the separation action → solves the blinking problem, but the balls are still overlapping after the first pause.
Thank you for your help!
There isn’t an easy way around this - it’s a challenge that’s been bugging many a GDeveloper for a long time. You can’t test for collisions between 2 objects of the same type and then separate them - I don’t think GDevelop will know which one to move and which to keep steady, and it may end up using just one of them for both actions. And this is even worse if there are multiple collisions
You may want to try (and this is a untested idea) to initially set the path for each object and then stop them before they head off on their merry way. As soon as you stop the object, get all of its path node positions and store them in an instance array.
Then use physics forces to push the object towards the first point stored in the array. Once the point is inside the object (and not that the object is at the point, as this may never happen with floating point precision), remove the first element of the array and repeat the process.
I think the physics engine should handle collisions between 2 physics objects for you, and not allow the overlapping of objects.
But, as I said, this is untested. It seems nice in theory, but there could be a snag that I’ve overlooked.
Thank you so much for your thoughtful reply. Would you have any other suggestions on handling crowd like behaviour?
If using pathfinding, the way I’ve done this in the past is to check if Ball is in Collision with Ball, pick the one that is nearest to the destination (inverted, so it picks the furthest), then set the speed to 0.
This sets it’s speed to 0 until it is no longer in collision. Here’s a link to the last time I posted this solution: Collision problem between two enemies - #6 by Silver-Streak