In this post you we will learn how to implement targeting enemy system similar to the one used in “Dark Souls” games.
Final Part 3 will build up on a project that we have done before. Part 1 of this tutorial can be found here : CLICK ME
This tutorial is relatively small. We will use Blueprints to implement:
- Line tracing to check if enemy is not covered by any object
Note: This tutorial was created with Unreal Engine 4.10.4 and it uses Third Person new Blueprint project.
To polish it up we want to add one more improvement. As you have probably noticed in Dark Souls or Bloodbourne, you cannot target the enemy when it’s hidden behind a big obstacle, around the corner etc.
To achieve our goal we will use tracing ray technique (raycasting). You can imagine ray (or line) as a simple line in a 3D space with a start and end position. What ray tracing does is to find out whether or not there was any object on its way. If you want to learn more about this topic you can take a look into documentation: Docs,
Let’s go back to the Character Controller Blueprint and modify the loop in which we check the closest distance to the target.
Now, before doing all of the calculations, we will first take a line from our player to the enemy and check if the ray hits something else than the enemy.
To do that we need to take a LineTraceForObjects function. To the Start and End nodes we will attach a GetActorLocation. Thus, we set Start to self, and End we set to the current element in the array.
 Added Line Tracing
One interesting thing that we can add here is filtering of the objects on the way of the ray. We want our ray to be blocked by three of them, all listed in the picture .
 Elements blocked by the ray.
On the picture  you can see how the result of line tracing looks like. We set the DrawDebugMode as Persistent. It will show the debug for tracing until we quit the game. On the picture you can see that when we pressed a button to target one of the enemies we were standing on the right-hand side. Ray towards the enemy on the left-hand side hit him, and the other one hit the obstacle.
 Red line shows the tray that didn’t intersect with any object, green one shows the ray after it did hit something. The hit points are marked as a red squares.
With this part finished we can get a wire from Out Hit and compare it to the current element in the Foreach loop. Whilst it is true to the enemy it means that there was no obstacle on the way, so we can continue.
To make it even more clear we can display some additional debug, like a name of object that was hit.
 Checking if the hit is equal to the current element in the array and displaying a debug.
After you’re done, your blueprint should look more or less like on picture :
 All of our changes
Here are all the project files that were used in this tutorial Google Drive.
That’s it! Congratulations! Now you have your own, Dark Souls-like targeting system.
We barely scratched the surface of the problem here in this series, that’s why we fell motivated to continue our tutorials. Stay tuned and very soon you will see the next series.
Thanks for your support. We are very excited after all good words you give us about our work. We read all your messages and suggestions. Next week we will start with a new series of tutorials so stay tuned!
If you like our work and you want to see more content from us (possibly we can do this even full time) please donate us!