Wednesday, December 4, 2024

Micro Tutorial: Comparing Tags on Trigger

 

    Yesterday(?) I wrote about how the tank turret in one of my games aims at the player, and a big part of getting that to work is letting the tank know that the player is even in range. This is done with triggers and tags.

    The tank itself is surrounded by a huge trigger sphere, but I don't want it firing off every time a crate is thrown through the trigger zone or a civi wanders through. So, after the On Trigger Enter block we go straight to a Compare Tag block hooked up (purple output/input) to an If block. So, if the object entering the trigger zone is tagged as the player, the script will fire and send the message "Liz_Seen" up to the parent object, which in this case it the tank, and that flips a boolean to let the tank know that the player is in range. 

    You can see in this picture there are two almost identical scripts, but note that one is starting with a Trigger Enter block and the other is a Trigger Exit. This way, the tank doesn't need to constantly check if the lizard/player is in range. It just gets notified when the player enters its range and when it exits the tanks range.

     Thanks for reading. If you want more maybe buy the game this script came from or just throw me something on Ko-Fi and I can justify making some more Visual Script write ups. I have a lot of other half-baked scripts to share.


 

No comments:

Post a Comment