Target system similar to “Dark Souls” | Blueprint Part 3 – Final


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.

Preview:


Line tracing

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.

t3p3_5

[1] Extending our loop

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.

t3p3_3

[2] 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 [3].

t3p3_2

[3] Elements blocked by the ray.

On the picture [4] 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.

t3p3_7

[4] 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.

 

t3p3_4

[5]  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 [6]:

 

t3p3_1

[6] All of our changes


 

Source files

Here are all the project files that were used in this tutorial Google Drive.

Also please check out video tutorial from  Rayziyun(Big Thanks): https://www.youtube.com/watch?v=gaULDBoG_oE

 


 

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!

Share:

23 Comments

Add yours
    • 2
      Adrian Lurendium

      As you can see there is a function GetAllActorsOfClass where you specify your target class. In our case it’s a Enemy_BP. You can choose a different that fits your needs. You can the wire out of the target class and promote it to variable and then you will be able to change it in your properties.
      If you have multiple enemy classes that that don’t have any parent class, you can create a Blueprint Interface (https://docs.unrealengine.com/latest/INT/Engine/Blueprints/UserGuide/Types/Interface/index.html) and apply it in all of your enemy classes. Then in Character controller you can use GetAllActorsWithInterface.
      Another fast but dirty solution would be to call GetAllActorsOfClass with different target class and combine it to one array.

      • 3
        G-dojjo

        Thanks for help and interest ^^ but i cant solve my problem :/ ( im trying different thing but i cant reach solve 🙁 ) (I think my unreal skills not enough for this 🙁 )

      • 4
        Lou

        Hi Adrian!
        I’ve nearly got this method working, although once I connect the master blueprint interface to the ForEachLoop, It won’t let me connect it to the distance from player check – because its target is the mainboss. Do you know how to allow this interface blueprint array connect to the nearest target and distance player check?
        Thank you for your time.

  1. 6
    Luiz

    man, i don’t know if i’m doing anything wrong, but if i remember, in dark souls the camera only look to the focussed enemy, but here the camera only stops in place

  2. 11
    Hasson

    Hey, I’m new to blueprints and this tutorial was extremely helpful, I managed to get everything working. I have a similar question to what someone asked before, how do I go about applying this to more than one enemy, as i will have more than one type in my game. I have read your previous response and tried to implement an interface but had problems connecting the loop array element to both the distance from player check function as well as the nearest target variable. i couldn’t work out where i was going wrong. I also tried the array method but that didn’t quite make sense to me i’m afraid. I would appreciate some help or feedback or even just a helpful screen shot so that i can figure out, where i am going wrong. Thanks in advance, apologies if this seems like a stupid question.

  3. 15
    youssef nasr

    Really Awesome Tutorial Man If you can help me out my character is using sword anim set pro the lock on system works but i need to make sure the character always faces the enemy any ideas how

  4. 16
    Lou

    Hey man,
    Many thanks for the tutorials, they are great. I have came across a small issue – I did this in an empty project and it works fine, but I’ve created it in my game too, and for some reason If I’m standing too close to the enemy and I press the target button for the first time, my camera faces in a complete oposite direction. I also get loads of errors at this point saying.. Accessed None ‘NearestTarget’ from node Return Node in graph change camera and player rotation when Target’ in blueprint warrior_BP (this is my main character)

    Please let me know if you have any idea’s and I’ll donate some extra monies. Many thanks,
    Lou

  5. 18
    ivan

    Great Article! But i have one little problem…
    So When i lock my target my follow camera is not following the target ( My enemy )
    How i can send you some screenshot? Thank you for your Work!

  6. 19
    ivan 21

    Great Article! But i have one little problem…
    So When i lock my target my follow camera is not following the target ( My enemy )
    How i can send you some screenshot? Thank you for your Work!

  7. 23
    GbFR

    hi super tutorial
    I have a bug when I have 2 AI on my card and I want to aim at one of them the system want to aim both at once my camera goes from one AI to another several times by second how can I fix that?
    thank you

+ Leave a Comment