Possible to stop objects in a group from overlapping each other?

This seems like it should be easy, but I can’t get the objects in an object group to not overlap themselves. What am I doing wrong or not understanding?

Condition: GroupName is in collision with GroupName
Action: Move GroupName away from GroupName

It is a limitation of GD because the engine doesn’t know which instance you are comparing to which and which one you want to move away from which.
The solution I can offer is a little complicated.

  1. Create a collider object to cover each object individually and hide the collider object.
  2. Then, link the collider object to the object it is covering using the Object Linking events
  3. Move the collider object with the object it is linked to.
  4. Check collision between the object and the collider object and if it linked or not.
  5. If the object is in collision with a collider object that is NOT linked to it, move the object away from the collider object.

Check collision only once a second or once every 2 seconds on a random object using a timer and the event to pick a random object to avoid checking collision too many times for too many objects in a frame because if you do it a lot, it is going to hit performance.

1 Like

Thank you so much! I’ll give it a shot.

This function does not work. What am I doing wrong? The “team” group includes all the objects indicated above, ie (player1, player2 etc …). I practically don’t want all these objects to overlap in game, so with that code I would like every object (playerX) in collision with every other player (all in the “Team” group) to move … but, in game this does not happen , they overlap when they reach a common X, Y position

Not entirely certain what is happening there.
My guess is that because each object is member of the group, each object also check collision with itself and somehow it is cancel out the move away action with all other instances.

The only solution I know to this is the one I have explained above.
I have an example shared here at the bottom of the page: collision between instances take a look:

It is a bit dirty and complicated but works.

1 Like

thank you so much. Unfortunately I will have to find another system because my “objects” are constantly moving to reach a given position (x, y), so after the “separation” they return to the same position … and then moved again. I have to find a different trick. However your suggestion is very useful and valid, to be used for less dynamic “objects”.

Try to create 6 separate groups that each will exclude the player you check the collision… For example squadra2 will include all players except player2 and so on… That should work…

In the example I shared I did not experienced anything like this but you push all the other players away naturally. Even if I move 2 players against each other with the same force they just stop until one of them no longer move or move with less force then the other push it away and if I use pathfinding to move a player it is just force it way through the other players and push them away no matter what but never return the same position.

Can you reproduce the problem in my example and share it?

Of course, for the moment I am doing various tests … as soon as I can do something that may be acceptable I will share it.