0
Answered

Conditions question

Skaterlion 1 month ago in Game Creator updated 1 month ago 2

Hello, first of all thanks for this awesome asset.

I'm trying to create a condition to activate an action after multiple objects are inside a trigger. I can get it to do the action with a single On trigger enter like a player walking in for example, but not sure how to go about doing the action only if player + other objects are in. Thanks!!

-Hugo H.

Unity version:
2018.3
Game Creator version:
0.9.9

Answer

Answer
Answered

Hi Skaterlion, thanks for the kind words :-)

If I understood this correctly you want to execute a Trigger after a certain amount of objects enter the Trigger's collider. You can do this in two ways: either using a custom Trigger or using the current available ones. I'd go with the second one if you're not comfortable programming. Otherwise, the first one is faster.

You'll need to count how many objects enter a Trigger's surroundings. To do so, you'll need a Trigger On Enter and another Trigger On Exit on the same game object. Every time an object enters the Trigger it should increase a variable value by 1 and when an object exists, it should subtract 1.


So, you'll also need a Local Variable. Create a new Local Variable component and create a variable of type Number. Give it a name such as "counter" and set the initial value to zero.


For each of the Trigger from above, create an Action. The On Trigger Enter should call an Action that uses the Add Variable action, increasing the "counter" + 1. On the other hand, the On Trigger Exit should do the same, but subtracting 1 to the "counter" Local Variable.

Now, imagine you want to execute a list of Actions when the counter reaches 5. You can create a Conditions object on the On Trigger Enter from above (executed below the Action that increases the "counter" variable) and check if the "counter" variable is greater or equal than 5.

If it is, then you can do whatever you want to do when there are 5 or more objects.


Creating a custom Trigger that does this should be fairly straightforward. You'd just need to merge the two On Trigger Enter and On Trigger Exit and create a private variable that works as the counter.

Hope this helps!

Answer
Answered

Hi Skaterlion, thanks for the kind words :-)

If I understood this correctly you want to execute a Trigger after a certain amount of objects enter the Trigger's collider. You can do this in two ways: either using a custom Trigger or using the current available ones. I'd go with the second one if you're not comfortable programming. Otherwise, the first one is faster.

You'll need to count how many objects enter a Trigger's surroundings. To do so, you'll need a Trigger On Enter and another Trigger On Exit on the same game object. Every time an object enters the Trigger it should increase a variable value by 1 and when an object exists, it should subtract 1.


So, you'll also need a Local Variable. Create a new Local Variable component and create a variable of type Number. Give it a name such as "counter" and set the initial value to zero.


For each of the Trigger from above, create an Action. The On Trigger Enter should call an Action that uses the Add Variable action, increasing the "counter" + 1. On the other hand, the On Trigger Exit should do the same, but subtracting 1 to the "counter" Local Variable.

Now, imagine you want to execute a list of Actions when the counter reaches 5. You can create a Conditions object on the On Trigger Enter from above (executed below the Action that increases the "counter" variable) and check if the "counter" variable is greater or equal than 5.

If it is, then you can do whatever you want to do when there are 5 or more objects.


Creating a custom Trigger that does this should be fairly straightforward. You'd just need to merge the two On Trigger Enter and On Trigger Exit and create a private variable that works as the counter.

Hope this helps!

+1

Hi Marti, thanks for the reply. Just by reading the instructions sounds straightforward but at the same time  I'm sure I will get mixed with setting up the counter. Will let you know how it goes, thanks!