Traces
We will use this to trace from the player's location to 255 units in front of the character. If anything collides with the trace, we will face the pawn to the right based on the pawn's rotation. This simple check will be enough to make our bot run along the walls indefinitely; so, perform the following steps:
- Pull the Return Value pin from GetActorLocation and drop it. Then, search for Vector + Vector.
- We now need to select Get Controlled Pawn and pull Get Actor Forward Vector from it. This contains vector information going in the direction that is in front of our pawn.
- So we will multiply Return Value by 255. This is the vector we want to add to the actor's location. This results in adding 255 units in the direction ahead of the pawn's current location.
- Now, we need to take the results of the addition of the End pin for the LineTraceByChannel node. This will trace directly in front of our pawn:
- Pull from the Vector + Vector node again, and this time we will plug it into the Dest pin for the Move to Location node. This will move the character forward indefinitely:
Let's try this out! Hit Simulate and look at your character move forward indefinitely! The only problem is that it can't avoid the walls just yet. We will change this by introducing a Select Vector node that chooses a different direction when a collision is detected by Line Trace:
- Once more, we will pull from the Get Controlled Pawn node and search for Get Actor Right Vector.
- From this node, we will pull the vector and multiply it by 512.
- We will add this to the pawn's current location. So, similar to what we did before going forward, we will add 512 units to the right of the pawn's current location:
- Right-click on the EventGraph section and search for Select Vector.
- From the LineTraceByChannel node, pull Return Value and connect it to the Select Vector node. Then, select A.
- Now, pull from the right location to A of the Select Vector node.
- Then, pull from the forward location to B of the Select Vector node.
- Select the Select Vector node and pull from Return Value into the Dest pin of Move to Location.
- Select the nodes and create a comment:
Let's see how this looks in-game:
It seems to work perfectly! This will create the chase for the next addition to this project.
Reviewing the current progress
So now, we've created our Hero character, who isn't much of a hero as he runs indefinitely, but that is another story. Here is the current round of the changes:
- We've updated the AI instructions
- We've demonstrated a basic sensory component
Now, let's move on to creating the Enemy AI.