Collision with the same instance

Unfortunately in GDevelop you can not make this kind of comparisons between instances of the same object. It is one of the limitations of GDevelop. The program just simply doesn’t know which instance you want to compare to which instance and then which instance you want to manipulate, delete, change…etc If you continue on this path it is going to only generate bugs in your game.

The only reliable solution is to have an invisible collider object linked and moved with each instance and when you want to check collision, distance between instances of the same object, do it with this collider object and check if they are linked. So the logic looks something like this:

If enemySmall is in collision with enemySmallCollider
And enemySmall is NOT linked to enemySmallCollider (meaning it was colliding with an other enemy instance)
Then pick enemySmall linked to enemySmallCollder (pick the other enemy instance it was colliding with)
Then stop enemySmall (the one linked to the collider it was colliding with)
Or move enemySmall away from enemySmallCollider (the one it is not linked to the collider)

I don’t have time to explain this in more detail, but this is the basic idea.
The order of execution is very important so you get a reference to the right instances of enemySmall and enemySmallCollider.
You also need to look in to object linking if you don’t know what that is.

3 Likes