Calculating length to trigger?

How do I calculate the length to a trigger?

I’d like it to function so that when the player presses a key it gives the distance between the player and the trigger?

Frank, how would this look as a bp?

One of the key difficulties I’m having is my game has a number of triggers in the same room, now they each pop up at different times using a move component to node, I’m trying to get it so that everytime I press “X” it gives me the distance to the specific trigger that’s popped up, I’d really appreciate some advice.

Perhaps get distance to triggers at a certain height?

Hi frank I’m probably explaining this really badly, I suppose I’m asking how do I perform the line trace?

Is there a way to get the distance of a trigger at a specific height, ie cycle through the triggers to find the one at height (z location) 57, The height that signifies the popped up trigger and return it’s distance to the player, say after pressing “x”

If you want the length between you and the trigger.
GetWorldLocation(You) -(minus) GetWorldLocation(Trigger) plug the result to VectorLength, this will get you a float value of the distance.

thanks for that but the problem is also how to reference a trigger.

as my game uses multiple triggers under the floor of the map, with each trigger moving up into proximity of the player at certain times I need to find how to reference that trigger when it’s up and out of the floor and then find the distance to that trigger.

id really appreciate some help with this guys

How do you want to interact with that trigger? By looking at it? By mouse click? What is the user supposed to do? Or do you just want to punch X and see if there’s any trigger in proximity?

Alternatively, you can use the method you’re already using for popping up triggers. Make the popping up trigger send self or its location to the player. Trigger can Get Pawn -> Cast -> give player its location. Or even the calculated distance.

Hi Everynone,

id like it so when I press x I get the distance to the trigger that’s popped up, how would this look as a bp?

id really appreciate your help with this.

Maybe get the trigger to communicate to your characterBP when it pops up.
On the Event in the trigger when it pops up, make a custom event in your characterBP that gets called during the pop-up from trigger BP. On the custom event, add a pin for triggerBPreference and pick the location in the character custom event as you would get the correct ref.

Trigger>POPUP>getAllAcrorsOfClass>get(a copy)>CallCustomEvent(character)(add self on pin)

character>customEvent fires>from pin>getWorldLocation(minus) your own worldLocation>plug into VectorLength.

Can you pls show me what this would look like as a BP, Im tearing hair out atm!

Additionally, I’m also wondering it this could work:

when the player presses a key, perhaps use get all actors of class to cycle through all triggers to find the one thats at a specific height (the popped up trigger is always at z location 57 the others are not) and output the distance between the player and that specific trigger, but no idea how to do this in a bp?

You’re not providing enough information. What does pop-up mean in this context, how is this triggered? How does the trigger know it’s supposed to pop up.

Besides the solution was mentioned a couple of times already. It not that easy to show because we do not have the setup you have.

The ham-fisted approach:

OnTriggerPopUp -> Get Player Character -> Cast To (your character) -> fire a Custom Event with a vector input that calculates the distance

In the Character:

In the Trigger:

Hi Everynone, thanks for that, sorry about the poor explanation, hopefully this will be better:

This is the set up I’m using basically triggers are kind of daisy chained in sequence, when one fires it removes itself from position in the room and pops up the next trigger sequentially:

TriggerMech.jpg

Do you think something like this could also work as a much cruder method, I’m not an awesome coder like you guys:
Perhaps.jpg
Just thinking out aloud, but I’d really appreciate your advice guys.

Hi Everynone,

I massively appreciate all your kind help in getting a solution realised, but am a bit scared tbh with using casting and custom events, also because of my very small brain, to reduce complexity do you feel the following might also work:

You’re not even measuring distance here… Besides that, if you measure the distance while the trigger is moving, you’ll get inaccurate results. Also, if you do your logic in the LevelBlueprint, it will work only in this one level. If you want to use something similar in lvl2, you now have to copy & paste the whole lot and rewire it. That’s OK if the level is unique, though.

Also, you’ve done this for 1 trigger only. How many times are you going to use the same code?

You should really turn that trigger into an actor and instantiate.

  • make your trigger into an actor with some logic that dispatches data when it’s triggered (unless you’re really dealing with 2 only)
  • the X action should be in the character / controller instead - not in the Level
  • measure the distance once the trigger is no longer moving (unless you’re ok with the inaccuracy)

I fully appreciate everything you say, but this will only be used in one level and the trigger wont be moving whilst being measured.

Can I please ask if you could recommend changes to my bp (I know its pretty crude) so that it definitely measures distance, particularly horizontal?

MASSIVELY appreciate your help