How to create a "trigger" with entering and leaving conditions?

Hello, I was wondering how do I create a condition for triggering an action when entering and leaving the area.

For instance, I created a sprite (and hid in “the beginning of the scene”) and added an event “player is in collision with the sprite” with an action “set opacity to another sprite” to make that sprite transparent.

The problem is it works but the inverted condition does not. So, when the player leaves the area, the sprite still stays in the condition of previous action (its opacity).

Here is the example,

Two things:

First, It doesn’t work because your second event is a sub event of the first one.

It is not possible to not be in collision with something when in collision with something. you need to drag the second event out of the first event.

You also probably want to use the “not” condition instead of inverting a collision condition. If you have more than one NewSprite7 in another location, your character will always not be in collision with one of them, so it’ll always be firing off. The not condition will fire off when the player is not in collision with ALL newsprite7s.

Second, you want to have the “trigger once” condition on both events, otherwise you will be setting the opacity every frame, which will be bad for performance.

1 Like

@Silver-Streak is RIGHT

1 Like

Thanks for the response. I have created two separate events of “in collision” and “not in collision”. Somehow it worked. But it only works, when “not in collision” is declared before the “in collision” event.

However, about performance issue, I tried using “trigger once” condition. But it gives me a weird flickering by changing the opacity. Thus when I enter the invisible “newsprite7” it changes the opacity of the other sprite and instantly goes back to normal. Doesn’t keep its changing state.

Here is the logic,

I am not sure what did you mean by “not” condition instead of “inverted condition”.

No reason to use subevents for trigger once/the action. Just put the trigger once under the condition.

Also, “Not” is a condition in the condition list. De-invert your other condition, add the “not” condition to the same event, then drag your condition into that Not condition (it’s a wrapper condition, it’ll make sense once you add it).

Make sure you add trigger once to that too.

1 Like

Thanks it worked! I hope I have written the correct logic.

1 Like