Download

Bi-directional trigger volume?

I’m looking for insights into setting up a trigger volume/actor/whatever that will trigger one thing when the player exits one side, and a different thing when the player exits the other side. Think of it like a plane; if the actor passes through the plane from side A to B, it will trigger event X, and if he passes from side B to A, it will trigger event Y.

Specifically, I’m doing a 2.5D segment of my game with splines which curve through 3D space to indicate the 2D plane the character is constrained to. This all works fine; but I have a “fork in the road” where I need to deactivate one spline and activate a different spline if the player jumps up onto a higher ledge.

I tried using a trigger volume with a flip-flop node, and two trigger volumes adjacent to one another, but both ultimately yield the same issue: it’s possible for the player to move forward into the trigger volume, then back up without passing THROUGH it, to activate the toggle. e.g. he can jump up to the platform to enter the branching path, walk back to the edge of it to trigger the transition back onto the main path, and then reverse direction while still ON the platform, thus following the primary path while in the space meant for the second one and spectacularly breaking everything.

Does anyone have any suggestions for this kind of “once you pass THROUGH the volume” switch, as opposed to the usual “once you TOUCH the volume” switch?

make a BP with two *overlapping *triggers.
introduce two variables which determine which of the two triggers you are overlapping atm:

overlapFront
overlapBack

on the OverlapStart/OverlapEnd you toggle those two flags.

together with the OverlapEnd event and the flag you know if the event is relevant and therefore you know which side the player leaves:

if overlapFront == false and EventOverlapEnd(Back)
→ player left at back end

if overlapBack == false and EventOverlapEnd(Front)
→ player left at front end

if overlapFront == true and EventOverlapEnd(Back)
if overlapBack == true and EventOverlapEnd(Front)
→ player went from one trigger to the other, but didn’t leave the area yet

Works excellent in theory but in practice this doesn’t solve the problem at all, presumably due to inconsistency in how UE4 handles “simultaneous” overlap events.

It’s still possible to walk directly into the trigger volume, turn around, and wade out again and trigger the wrong message, and I suspect the reason is because both EndOverlaps occur within the same frame, so the engine just processes them sequentially based on whatever trigger happens to be higher in the event stack.

I had post same solution but deleted as enlo did it, but with two triggers, one overlapping the other on a side. When you exit the big one, you check with bool that you overlap the second one (set true on enter and false on exit). If yes event x if no event y.

if i understand well , you want to detect when the exit the trigger from the left and when from the right
you can try this

on end overlap -> if (otherActor.location.x>trigger.location.x) -> exit from right
else ->exit from left

MHouse that’s a perfect solution.

I ended up tweaking it a bit so it could work in any world-space orientation (I find the delta between the actor’s rotation and the look-at rotation between it and the player to determine if the player EndOverlaps nearer the front 180° or the back 180°) but it’s consistent and reliable.

Yep the way I do it is with 2 triggers next to each other. So I only want a trigger event to happen if i come in from the left hand side so I set a boolean to true when i hit the left trigger and then the right trigger only calls the function if it’s true. Then you can do the same thing in reverse.

Of course the overlapping space would have to be bigger than the character itself to avoid this.
But then Mhousse1247’s solution is much better anyway :slight_smile:

You could also use the dot product between the pawn velocity and the trigger forward vector. The result, positive or negative values, will tell you which direction you are exiting the volume.

thanks, you just saved my college’s final project :heart:
for those who want a three-dimensional solution of @Mhousse1247