[SOLVED] Delete if X is colliding with a ZONE with variable set to false unless X also collides with ZONE with variable set to true

Hi! Please read. It’s long but I explain things clearly. I’m struggling with implementing a certain type of system.

My game has “SPAWN ZONES”. Many of them overlap with each other:

My SPAWN ZONE -object has a boolean object variable called “Player_Inside_This_Zone”. It’s FALSE by default. When the player gets into collision with a ZONE, it’s variable gets changed to TRUE. When the player leaves a ZONE, the variable gets changed to FALSE again.

I have enemy spawners all over my map. They spawn one set of enemies whenever the “Player_Inside_This_Zone” variable is set to TRUE in the zone instance they occupy. This works. The enemies are currently spawning as hoped.

The problem I have relates to the deletion of spawned enemies. I want my enemies to get deleted when I exit the ZONE they occupy. You can almost say that I want my enemies to get deleted when they are in collision with a ZONE which has “Player_Inside_This_Zone” set to FALSE. Something like this:


But this doesn’t quite work. These events delete too much. Consider the enemies which spawn in places where 2 ZONES overlap. As long as an enemy is in collision with one ZONE with “Player_Inside_This_Zone” set to FALSE, it will get deleted, even if that same enemy is also colliding with another ZONE with “Player_Inside_This_Zone” set to TRUE. I need to save these enemies from deletion.

What I want in a nut shell:
Enemy must be deleted if they are in collision with a SPAWN ZONE which has it’s “Player_Inside_This_Zone” set to false UNLESS the enemy is also in collision with another SPAWN ZONE with “Player_Inside_This_Zone” set to true.

How do I achieve that?

Thank you

Switch these 2 and tell me did it change anything
image

1 Like

I switched. I don’t think it did anything. It looks the same: many enemies disappear immediately after spawning.

So let’s start by checking if you variable is correct

Set opacity of spawn zones to 255 if their variable is true
And to 100 if var is false

1 Like

Variables work. When I enter, ZONES are not transparent. When I exit, they are.

So now you just make event
Enemy is in collision with spawn zone
Spawn zone variable = false
INVERTED Spawn zone opacity = 255
Delete enemy

1 Like

This doesn’t quite work either.

GDevelop_JsaetYRj0l
Currently the enemies only stay on screen if the player is touching a place where two SPAWN ZONES overlap.

I’ve something similar in my game…(cos performances matter)
imo zones should not overlap…enable the grid on scene editor and place them with snap without overlap…then u may have a better clue on waz going on…

Implementing this system without zones overlapping would be easy, but I think it creates other problems. I need the zones to overlap.

Wait wait wait
I am not sure where and IF you need repeat for each
So test each scenarios
GTFO with variable
And leave only opacity change
Now you only need set opacity to 100 when spawnzone IS NOT in collision with player
And to 255 if it is in collision with player

And now IN SEPARATE EVENT

Enemy is in collision with spawn zone
Spawn zone opacity is 100

Delete enemy

So basically you have only 2 events
And either both of them need for reach or none or one of them
BUT if any of them need then 1st event needs for each for spawn zones
2nd needs for each for enemies

1 Like

Wait i just realized what i wrote above did run full circle cause if enemy is in collision with zone that opacity is 100 while being in collision with zone that opacity is 255 then enemy would still get deleted

I am thinking of a way to bypass that

1 Like

Ok
Try it with NOT
Instead of inverting condition

Add condition and type NOT in search bar

Then add it

And put under it not inverted enemy is in collision with spawn zone

So it should be
Condition
Spawnzone opacity = 255
NOT
Enemy is in collision with spawnzone

Action delete enemy

1 Like

I tested 4 different scenarios. Are these what you were looking for?

1.


This doesn’t work. Enemies only stay on screen if the player is touching a place where two SPAWN ZONES overlap.


2.


It’s the same with this.


3.


This doesn’t work:
GDevelop_bYquy99SES


4.


This doesn’t work:
GDevelop_8ZAxMfqNId


Please clarify if I misunderstood something :slight_smile:

EDIT: I just noticed your new messages. I’ll read them now.

Look your issue is due you checking 2 different things for same type of object while these objects overlap

So if you check if player is not in collision with spawn zone
then even if enemy is in collision with spawn zone which overlaps one with which player is in collision
You will delete enemy cause one of zones is NOT in collision with player

So only solution would be to delete enemies if they are not in collision with spawnzone with which player collides

And i think for that you need NOT statement

1 Like

Right. I’m familiar with it.
I’m just not sure how I should use it in this particular scenario.

I’ll try what you suggested:

Before I do so, I want to make sure you didn’t misspell anything. Did you really mean “Spawnzone opacity = 255”? Shouldn’t it be “Spawnzone opacity = 100”? Or did you mean to put the “Spawnzone opacity = 255” under NOT? I’m asking because it seems wrong to me.

Thanks : )

How about you try instead of asking?

Asking can save us both time. I don’t mean to offend you.

You are not offending me
You are in fact wasting only YOUR time by asking something you could simply check yourself

Even if you think i misspelled something you would faster check each possible combination rather than asking

I tried 8 different versions. 4 without “for each”. 4 with “for each”. None of them work properly. Results are listed below.




Doesn’t work. Enemies spawn at correct time but never get deleted. They also do not respawn.




It’s the same with this.



(I’ll only post the “De-Spawning” section from now on. Events before remain unchanged)


Doesn’t work. Enemies spawn and get deleted correctly when the player enters the SPAWN ZONE from nothing and goes back to nothing. But if the player moves from a SPAWN ZONE to a new ZONE (exiting the previous one), none of the enemies from the previous one get deleted. In fact, new enemies are sometimes made, which confuses me. I don’t get it. One thing is for certain: this isn’t it.




Doesn’t work. Enemies spawn at correct time but never get deleted. They also do not respawn.




Doesn’t work. Endless enemies spawn when I’m inside ZONE and never get deleted.




Doesn’t work. Endless enemies spawn when I’m inside ZONE and never get deleted.




Doesn’t work. Enemies spawn and get deleted correctly when the player enters the SPAWN ZONE from nothing and goes back to nothing. If the player moves from a SPAWN ZONE to a new ZONE (exiting the previous one), none of the enemies from the previous one get deleted. Spawners that aren’t on overlapping ground spawn one new set enemies. Spawners that are on overlapping ground spawn infinite enemies.




Doesn’t work. Endless enemies spawn when I’m inside ZONE and never get deleted.

nope…
is there any good reason to have zones overlaps?
…none that i can’t see…so better be clean