Tutorial - Trigger zone – Ylands

From Bohemia Interactive Community
Jump to navigation Jump to search

In this scene we are working with Game Logic objects called Trigger zone. Most of Game Logic objects are “virtual” - they do some things regardless of their position in the game (actually, it is often a good idea to put those aside, next to each other so they don’t clutter the scene), however, Trigger zone isn’t one of those - its position and shape matters. It is an area that detects if someone (player, animal,...) or something (projectile, item,...) enters it or leaves it.

If it does, the Trigger zone executes either On Trigger Enter or On Trigger Leave in its script.

By adjusting Trigger zone properties you can change the zone’s shape but more importantly set when and to what objects it reacts. You set it so that it reacts to a projectile, a player and much more. Also you can decide if the event On Trigger Enter is executed if there’s already some other valid object inside it. And last but not least - how many times it should be triggered. If you want it to trigger always, just leave the value at -1.

The Door Frame Trigger Zone

So the script attached to the Trigger zone placed in the door frame does this:

  • When the player enters it writes a text into a console
  • When the player leaves it writes a different text into console


Writing text into the console is a great way of checking what part of your script is executed, what value variables have at a certain time and much more. However, please note that when you test a game in the Editor the console (chat window) isn’t cleared. To avoid potential confusion caused by older console text, you can clear the console by typing /clearchat into it.

The Dummy Trigger Zone

The second trigger zone in front of the dummy does a similar thing - it shows a text when entering and leaving, but this time it shows it inside a bubble above the dummy.

The instruction may look a bit complicated but it’s actually quite simple. It contains following fields:

Entity: above which entity should the bubble appear

Text: what will the text say. This is where things start to get interesting. We could say simply “Hello!” but instead we decided to say “Hello” + name of the player who has entered the Trigger Zone.

You may have noticed that this instruction has a parameter called Trigger entity. When anything enters the zone, this will contain the object which has entered it. We could have just used this to be shown inside the bubble, but we wanted more so we created a more sophisticated text by combining two strings - the “Hello,” part and the entity (the entity isn’t actually a string but when the script sees we are trying to use it as one, it transforms it into entity’s name).

Hide speaker: this just affects whether the text will have its speaker name in front of it - in this case, if we enabled it, the text would show something like “Dummy target: Hello, SomePlayer”