Collision with the same instance


#1

Hey:)
I’m stucked with this: Collision with the same Instance
I try to make this:
if “Enemy1” distance to Enemy1" is lower than 20"…then … stop on of them until the distance is great enouhg. But only when they have same “direction” …so nothing should happen if they are facing each other.
Really could need some Help here^^…I tried it the whole day :sleepy:

greetings^^


Collision on Objects Same Type
#2

Hi,
“Stop one of them” - which one? :upside_down_face:
For the direction, there is a condition “object is turned towards another”.
Cheers


#3

Ahh my bad sorry …I meant one of the instances… for example if there are Enemy1 id =1 and Enemy1 id=2

Thanks! i didnt thought about that! and i never used it before^^
Do I have to use “0” or “180” as angle? :thinking:

cheers :wink:


#4


i think I made it! What do you think about it? Does it looks correctly?
(I used “0” as angle)
I think it does what its supposed to do. Maybe to “good”^^. I will do some better gameplay tests Tomorrow, and keep you updated^^
Thanks for your Help :pray:


#5

I have a new question… but …also to Collision with same Instance…

there are three "instances of the object “EnemySmall”…the 2nd and 3rd are close to eachother … the first a bit away… it works perfectly if I have “delete EnemySmall”…with each collision player lose 25 “playerHealth”…if i do it without “delete EnemySmall”… the 2nd and 3rd “count as one collision”… and player lose only 25 for both and not 50.
Do you have an idea why? greetings :see_no_evil:


#6

try to do it with a “for each” event?


#7

Hey thanks for your reply… Did you see the photo? I did :see_no_evil:… Or do you mean something else? :thinking:
Greetings! :grin:


#8

what should happen with the enemies after he collide with the player?


#9

never mind. I should use a cooldown timer to all of your instances, because without a cooldown they substract PlayerHealth all the time. so, if you don’t want to delete them when they collide I think you need to use it. or you should push either the player itself or the enemies.

this is my screenshot with the cooldown timers.


#10

You should remove the highlighted line (id variable) because it’s useless… and perhaps conflicting?


#11

Thanks for you time :pray:
I removed it…still the same problem :confused:


#12

Variable id of enemySmall = enemySmall.Variable(id)

Of course it is! That’s always true! (A is always equal to A).


#13

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.


#14

don’t worry… thanks! thats a very smart idea actually… i understand what you want to say…but i’ve trouble with recreating it:


(while testing, only one of “Tr1” and “Try2” are active)

can you see the mistake?
Greetings


#15

Instead of the inverted “take into account” which is kinda confusing, I would try:
EnemySmall is in collision with Collider
EnemySmall.Variable(id) =/= Collider.Variable(id).


#16

Thanks! Works! I can tell them apart now!
But i’m struggling with, recognizing which direction they have… or if they are facing each other or not… I tried it, for example with:
Text variable Direction of EnemySmallCollider= EnemySmall.VariableString(Direction)

It doesn’t work… :triumph:I checked it in the debugger mode…


#17

There is a condition “object is turned towards another”, give it a try.


#18

like this?
They get seperated always…, no matter which rotation towards they have :frowning:
do you have an idea whey or how to fix it?


#19

I don’t understand what you’re trying to achieve, so I can’t help specifically.

Regarding “no matter which rotation”, the condition “rotated towards” has an angle setting you can use to broaden/restrict the “field of view” of the “viewer”.

When you get stuck, the best is often to open a new scene as sandbox and try specifically the conditions and actions you want to use, on dummy objects. And when you understand how the events cooperate/work, go back to your project and try it.


#20

I want to achieve, if one enemy, is in collision with in his instance/ or another, and they have the same direction, they shall separated, so they can’t go inside each other. Because sometimes it’s hard to see if its one enemy or two…
But, if they have different directions, or facing each other, they have to “pass each other” otherwise they blocking each other… I hope I explained it well🤔 otherwise i could make pictures, to make it clearlier🤔

Hmm i didn’t understand it completely :thinking:sorry :pensive:

I’m already doing it! But clearly a good advice! :pray:t5:

Thanks for helping me out so far🙏🏾