Distance to problem?

Hi All,
I was wondering if someone maybe able to help with a very annoying coding problem i’ve got.

I need to find distance between player and 4 moving triggers in the same room.

How the map works is player needs to find location A then B in a room from location 1 after which they are moved to location 2 in the same room but they now have to find location C and D.

By moving to location 2 (and because I’m pants at programming) I’ve moved the triggers for location A and B below the ground so the player can’t mistakenly walk on them to activate them.

Now here’s the tricky bit if the player can’t find location A, B, C or D, I need the player to press a key from their current location in the room that will show their distance between them and the trigger.

I also need to be able to test this to ensure if I get some values I can run a calculation to ensure its accurate.

I’ve tried the “get distance to” function on keypress between each trigger location in a variable that’s sequentially updated when each trigger is moved into the desired location, but it’s not working and I can’t test the data I get back to check.

I’d really appreciate some help!

Distance to mechanism

Trigger movement and variable updating
More movement stuff but with a delay

You’re giving yourself an unnecessarily hard time by not destroying the used triggers.

When the player overlaps a trigger, the actor should destroy itself.

Then, all you ever have to do is find the distance to the next trigger.

1 Like

I MASSIVELY APPRECIATE your help clockwork man!

Although, that sounds quite difficult to do or make sense of even, for me as a very amateur programmer, how would I repurpose my BP to include the functionality of yours?

The reason why I haven’t destroyed the trigger (I sorta looked into this) is because in my game we try to give the player 3 attempts to learn where each of the triggers are before on the 4th attempt they’ve gotta do it for real.

As such I thought reuse was the way to go?

No problemo… :slight_smile:

So, keep them in an array ( like in the pic ), and have an int to show which trigger is the current one.

You can setup an array of triggers in the level BP:

I only set the first one, but you get the idea. You have an int which tells you which is the current target. Then you can make a function which gives the distance to the current target:

You call the function like this:

Screenshot_3.jpg

Or, if you want to be snazzy, you can make the function ‘pure’

Screenshot_4.jpg

Then, the call looks like this:
Screenshot_5.jpg

Tell me how you do…

Hi Clockwork,

One of the problems I have is for my map I need to train the player in finding two trigger locations in a room by having them do it 4 times once they’re comfortable with finding these 2 items, they then have to find another 2 from a different location in the map similarly 4 times.

They then return to their first position in the room find the first 2 triggers then are moved to the second position to find the last two to complete the game.

I’m using separate triggers each time (my BP looks like bad spaghetti!) is this the correct way to do it, or should I simply use 4 triggers that are enabled and disabled each time instead (or use separate triggers that are destroyed sequentially as they’re used)?

In theory would that need changing the code above?

VERY SORRY for being a pain.

I’d really appreciate your help.

No worries. You can do it by using only 4 triggers and my code above.

But: change the array of triggers for each part of the game, that’s all.

Tell me if you don’t get it and I’ll explain in a bit more detail.

Gimme 10, doing some now…

Somthing like this:

I’ve not actually tested this, but maybe you get the idea. In fact, we don’t use the overlap of the triggers at all, because in this case, it just complicates the situation. We’re just using them as markers.

You could also do a more elaborate version that does use overlap and destroy, and spawns the boxes at the start of each round. But that would be a lot to explain here.

Tell me how it goes…

( you wanna make that distance to check 100 rather than 50 ).

1 Like

Hey I Massively appreciate this!

I can’t thank you enough Clockwork, it’s guys like you that make these forums what they are, I owe you one.

I’ll try putting this together tomorrow.

( I did test it actually, it works… :wink: )

Oh Man, I can’t even set up the trigger array, I’ve added an array, with a variable type of trigger box, but in its default values section I only have the option of selecting one of the triggers that already in the map, not the option of adding multiple array elements you have in yours?

Could I be really annoying and please ask for a step by step, I’m going mad trying to figure this out on 4.21.

I’d really appreciate your help.

Triggers you have in the map, that’s right. That’s all I did.

So for round 1 ( say ), you only put certain triggers in the array, from the map.

Am I missing something here? :slight_smile:

When I try to set up the trigger array I can only get 1 trigger reference in there not the multiple values for multiple triggers I should and like you do in the image?
If you could do a step by step I’d really appreciate it because as I’m stupid, I’m doing something very simple wrong and I’m sorry for the hassle this must cause

You have to click the first one in the level, then go to the BP and right click on the background to get the ref.

Do that for each box.

Does that work?

No it won’t allow for more than one value, would it be possible to make a quick video or outline of each step you took to create your BP?

will do…

1 Like

Like this:

select trigger

make array

put trigger 3

select another

assign

Thanks Clockwork, I’ll give this a shot when I get back from work this evening.

1 Like

I’m REALLY SORRY, I’m going to look really really stupid but I can’t get it to work, I can’t seem to even find the variable types.

I’m honestly SORRY to be a pain but would it be possible to list which exact variables you’ve used to construct the BP as I’m really pulling my hair out, a step by step would be massively appreciated.

I know you’re very busy, but I’d really appreciate it.

Really sorry man.

Let’s take it step by step. Does this work?

Click on box in level, right click in level BP, make box variable

?

Have you sussed this? When you click on something in the level and go to the level BP. When you right click you get:

Screenshot_2

which gives you a ref to the thing you clicked?

yes that bit’s fine, it might be the type of trigger array