Triggering Trigger Volumes
I want my character to have directional triggers, so that interaction only occurs in the direction that the Hero is facing. In order to do this I'm going to make four separate trigger volumes that will flip on and off based on movement.
Trigger Volumes
Colliders can do some cool stuff. They don't have to be just physics based, though. We need trigger volumes for our Hero.
I created four box collision components and attached them to my Sprite component, then adjusted their sizes and positions to form a cross.
Three types of collision shapes. |
Set up in the hierarchy. |
What we want is to make these into triggers, since we don't want them to physically block anything. Name each one with a proper direction for referencing and then adjust the Collision settings in the Details panel for each with "Collision Presets" set to Trigger.
Now these four volumes will send out overlap data. But we don't want them on all the time. The goal here is to have them switch on and off. We only want the volume in the direction our Hero is facing to be on at any moment.
Red Light, Green Light
We previously set up an enumeration type variable that stores our direction data. This can be reused now for our triggers.
In the Event Graph for our Hero's Blueprint make a new function. Name it "SetTriggerDirection". Open it up.
Grab the CurrentMoveDirection variable from the left and Ctrl-Click and Drag it out into your new function. We want to get a "Switch on E_MoveDirection" node. This will execute only one pin at a time based on what the enum variable is set as.
Night time in the switchin' yard... |
As we use our movement keys the CurrentMoveDirection will change. We need set up a series of "Set" nodes for our trigger volumes so that they turn on and off based on that switch's execution.
Ctrl-Click and Drag a reference to each of the trigger volume components. Get the "Set Generate Overlap Events" node for each one. The bool value just needs to correspond with the switch direction.
You'll need all four set for each direction accordingly. For the Up direction, check the bool for the Up trigger volume, and uncheck it on Down, Left, and Right. And continue with this pattern on all directions.
You should end up with something like this:
Full of triggers. |
Now we just need to call this function. We want to do that after we set our animation, where the CurrentMoveDirection variable is set, on every frame. So attach it to the Event Tick after the SetAnimationFlipbook function.
And that's it! You now have collision volumes that will turn on and off based on the direction your character is facing. We'll use this to create some interactions with objects and NPCs eventually.
- Matthew
Comments
Post a Comment