Payday 3 Detection Meter And Chase System - Unreal Engine 5 Tutorial (part 2/2)

ai

Next, what we're going to do is go to class settings and add the interface the same way we did on the AI, and then again go to our interfaces, and this time we're going to get the start detection and stop detection events, as you see here, and I'm just going to move these over here into some nice empty space and move the stop detection down just so we have a little bit more room here to start with.

Then what we're going to do is get the detection meter widget, drag it out of this, and we're going to get the progress bar. If you gave it a specific name, then get that, obviously, but I just left it as progress bar 48. And then, out of this, we're very simply going to set visibility, like so, and we're going to connect that into there, like this, setting it to visible.

So this way, it's now going to show when the AI starts detecting because we're only going to call this when we do want to start detecting. Then after this, we're going to add timeline, and I'm just going to name this one fill, detection meter. Opening that up straight away by double clicking on it, we're going to add a track, add a float track, and I'm going to name this one the fill icon.

blender

And set the length to whatever you want, so I'm going to set mine to be 3 seconds. This is how long it's going to take to fill up the meter. Now, I want it to take 3 seconds, but again, you can put it at whatever you want, so it could be 1 2 3 4 5 or any number you want. In here, we're going to right-click the add key to add a curve float with a time of zero and a value of zero.

Then right-click the add key to add a curve float with a time of the length of your timeline, which is three and a value of one, so we're going from the start to the end of the timeline like this. We go back to the event graph, and you can see we now have this float track here. This is basically just going to be the percentage of the progress bar.

So if we were to hit Play Walk in front of the AI, it's going to fill up, but it's not going to stop, and it won't empty. So we can do that very easily; we can get our stop-Chase event here. Then we want to get a reference for our timeline, so under the variables tab, we have components, and we get the fill detection meter, which is the name of our timeline.

chase

Out of this, we simply get a stop to stop the timeline from filling up, and then we go in reverse. So it's going to stop it from filling, and then reverse, so it's going to empty it. Now if we hit play, we can see that it's going to do that perfectly; it's going to fill and then empty when we are in sight and not in sight of the AI.

But we also want this to now work to chase us because when it fills up, nothing's going to happen; it's not going to start chasing us; it will just stay as it is. So we can do this very easily. We're going to come out of the direction of the timeline and get a switch on the E timeline. Direction: connecting that into the end of the timeline.

If we're going forward, we want to start the chase because we're filling it; if we're going backwards, we're emptying it, so we want to take it off screen and stop the chase if it was already chasing us. So we're going to get a reference to the AI from the event, and then simply start Chase with the message there, connecting that into the forward of the switch, and that's all we need to do for going forward.

detection

However, if we want to do something first, we want to get a retriggerable delay once again, setting this to 5 seconds, for example. Now you don't need this, but this essentially means that 5 seconds after it is emptied, it will be taken off screen, because this just looks a little bit nicer than immediately removing it.

After this, we want to remove it off screen, so we want to come out of the progress bar here and then set. Visibility, and we're going to set this to be hidden, like so, and again. I'm just going to double click this to get some rot nodes, and then finally, last but not least, we just want to stop the chase so we can come out with the AI reference again, the same one going into stop Chase and just do stop Chase, message like this, connecting that in like this.

detection system

And then, if we can get away from it, it's going to empty and then stop chasing us, which we should hopefully see, but I might not be able to get away from it. As we can see, it's empty and stopping chasing us, and now if I go back in front of it, it will do the whole thing again; it's going to start filling up, and then if I'm out of sight, it will stop, and then once it fills all the way up, it will start chasing us perfectly like so, and now the next step is going to be to get this to actually face where the AI is because it's just pointing forward no matter where we are looking, so we want it to point towards the AI at all times so we know which one is detecting us.

This is very simple. What we're going to do is we're going to go back into our widget blueprint, so for me, that's a W detection meter, and we're going to go straight to the event graph. We can delete the event PR construct and the event construct, as we just need the event tick. We're going to add a variable naming this Ai, and we're going to set this to be a character object reference.

far cry

As mentioned previously, that is just because my AI is a character. If yours is a porn, for example, then set this to a porn object reference. We're going to drag and drop and get this here, then we're going to right-click and convert to validated, then get connected to the event tick. We are then going to get the progress bar and, out of this, the render.

Transform angle, that is basically just setting the rotation of the progress bar, now we want to do a little bit of maths to figure out the angle so again we want to figure out the angle to point towards where the AI is relative to where the player is looking, so this is actually a lot more simple than you may expect, we're going to firstly right click and get player, character, then out of this we're going to get actor location so just where the player currently is, then we're going to get a reference to the AI and then also get act location so where is the player and where is the AI, then coming out of the get ax location for the player we're going to find look at rotation, that one is going to be start and the target is going to be the AI.

games design

Location, so now we have the lookout ration from the player to the AI, but there's still a little bit more math, so if we right-click the return value, we can split the structure pin, and what we're going to do is right-click and get to the player character once again, and out of this, we're going to get control.

Author:
Source
This is part 22 of a Payday 3 detection meter system. This will show a meter on screen which fills and empties based on if an enemy AI is looking at the player.
Similar articles: