ダークソウルズと同様のシステムをターゲットに青写真|パート1


In this post we will learn how to implement a targeting enemy system similar to the one used in “Dark Souls” games.

This tutorial will use Blueprints and it will contain:

  • Switching the mode between targeted/un-targeted enemy.
  • Create a visual indicator above the enemy that will be displayed in target mode.
  • Implement Camera behaviour for target mode.

Note: This tutorial is made in Unreal Engine 4.10.4 and it use Third Person new Blueprint project.

1 new project

 

 

 

 

 

[1]New project Window

 


Create enemy

Open the Content Browser and right click on the ThirdPersonCharacter blueprint then select Duplicate from drop-down menu.

After that name the new blueprint “Enemy_BP“.

2 duplicate blueprint

 

 

 

 

[2] Duplicate the ThirdPersonCharacter blueprint. To do that you can also select a blueprint and press Ctrl + W

Open the Enamy_BP  and remove Gamepad input, Mouse input,

Touch input and on the left side of the blueprint in Components remove CameraBoom and Follow Camera in your Enamy_BP:

3 clean up blueprint enemy

 

 

 

 

[3] Enemy_BP

 


Create Target Visual

Now our project is set-up and ready to work.

The next step is to create visual object that will show above the enemy when the target mode is on.

Press Add Component on the left-hand side of the Enemy blueprint then add a Sphere and name it TargetVisual.

4 add sphere and name it TargetVisual

 

 

 

 

 

 

 

[4] Drag a Sphere from the Components tab

Make the TargetVisual a child object of a Mesh by dragging it on the Mesh.

5 put in child mesh

 

 

 

 

 

 

 

[5] Target visual is a child 

Click on the TargetVisual, then on the right-hand side of the blueprint find Sockets and then in the Parent Socket press the magnify glass icon to find a spine_01.

  Note: Parent Socket will make our TargetVisual object move with the bone we selected; in this case it’s spine_01,

  also more information about sockets can be found HERE.

6 Socket

 

 

 

 

[6] Details of our Target Visual

After parenting socket you should notice the weird position of TargetVisual, to fix this go to Transform and in location set X, Y and Z to  0, 0, 0.

It will move the TargetVisual to the spine_01 location.

From here you can adjust your TargetVisual to location that suit your personal need in this case TargetVisual will appear above the enemy.

9 place your targetVisual to postion you are ahppy

 

 

 

 

[7] Vieport view

Last important step we have to do in setting up our TargetVisual hidden in game.

To do this, go to details tap and type “hidden” then in Rendering make sure you mark Hidden in Game.

8 type hidden and select hidden in game

 

 

 

[8] Set rendering to hidden

 

Now when your TargetVisual is ready, save the Enemy_BP and go back to the Content Browser.

 


Game_ BPI

In the Content Browser, right click then select Blueprints -> Blueprint Interface and name it Game_BPI. To make long story short, interface is usually used when many classes need to implement certain behaviour. See the documentation to learn more Docs.

10 gameBPI

 

 

 

 

 

[9] Add a new Blueprint Interface

Open the Game_BPI and add a new function called TargetLockON then save it and go back to the Enemy_BP.

11 in Game_BPI target lock on

 

 

 

 

 

 

 

[10] Function view with newly created TargetLockON

 

Once Enemy_BP is opened press on the Class Settings icon to will open an extra tab on the right-hand side of the blueprint.

12 Class setting

 

[11] Class settings

 

In Class Settings tab find Interfaces area and then click on the Add button to add our Game_BPI.

13 add interface

 

 

[12] Hook-up our new blueprint interface

 


Trigger Target Visual enemy blueprint logic

In Enemy_BP find some free space and add all the necessary components as shown in picture [12]:

14 triget target visual in enamy

 

 

 

 

 

[13] Set Hidden in Game

 

This event will be used to switch our TargetVisual object On or Off.

 


Create GameInstance

Blueprint can be inherited like C++ classes. Back in our Content Browser right click to add a new Blueprint. It will open a new window called “Pick Parent Class“. Then below All Classes type gameinstance.

Select it and add it while using the name “Zone_GI

15 game inscane

 

 

 

 

 

 

[14] Type the “GameInstant” to fast-find the parent class you are looking for.

Once it’s added, it should look like the example shown in the picture [14]:

16 zone_GI

 

 

 

 

[15] Zone_GI in the Content Browser

Open it up and add a variable called TargetPosition then press on the closed eye icon next to a newly created TargetPosition variable. Now the eye should be opened.

It will make the variable public so you can get access to it form our Enamy_BP.

Click on the TargetPosition and on the right side of this blueprint change variable type to Vector.

Save and compile blueprint.

17 target position

 

 

[16] If you don’t want to lose your progress, remember to often save your blueprints. If your logic doesn’t work, maybe you can check if the bp was compiled

Press on the Edit > Project Settings… then select Maps & Modes and change or add a game instance. (Zone_GI)

18 project setting change game instance

 

 

 

 

[17] Project settings view

 


Send Enemy Target Location

Go back to the Enemy_BP and create a new function called SendTargetLocation then make it look like picture below.

This function will return enemy location, that we will be used later to move our player camera around.

19 game instance send target location

 

 

 

 

[18] Enemy_BP – Send target location

One more thing that we need to do is adding our function to the Enemy_BP. In order to do that go to the Event graph and add a New Event Called
Event
BeginPlay then we need to add a  DoOnce and  Set Timer by Function Name.

In Set timer by function name set:

  • Function name – SendTargetLocation.
  • Time set to 0.05.
  • Looping marked as yes.

This will make our enemy send target location every 0.05 second after game start. This is not a perfect implementation, but I want you to see that it’s possible. Later on, in next tutorial we will create a new method that will be called every time we need it.

20 set enamy on stat position send event

 

 

 

[19] Send target location

Now that our Enemy_BP is finished, we can save and compile it  and drag it to our game scene.

 


Adding Target Input Action

Before we add blueprint logic to our Player we will set out are special Target Input action.

To do that press Edit > Project Settings.. > Input > Bindings then add new Action Mappings call Target and add any Input you want to it in our case we use key “T” that key will trigger our target system.

21 add input action target

 

 

 

 

[20] Bind an Input

Now we can go and open our player blueprint.

 


Add Target logic to player blueprint

Open player blueprint in this case it’s called “ThirdPersonCharacter” inside it, add new input event call Target and add logins as on picture below:

Make sure that TargetLockON using interface Game_BPI.

22 comunicate with target

[21] InputAction Target

Now double click on Timeline_0 and set length to 0.2, auto start to yes and lopping to yes.

23 timeline_0

 

 

At this stage of our tutorial we can finally press play and test if our TargetVisual will appear above the enemy’s head after pressing our InputAction Target button.

If it works we can move to the final part of this tutorial.

 


Camera Target Movement Logic

We almost there now we have to go back to player blueprint to finish our Target logic.

In Cast To Zone_GI and drag a wire form “As Zone_GI” to GET a transform Position.

24 get target position

 

 

 

 

[22] Get a transform Position

Moving on a copy logic bellow to make camera move when enemy is targeted.

(here more information about logic)

25 blueprint cam[23] Setting up rotation

 


You’ve made it to the end of Part 1 CONGRATULATION !

Now go and test your targeting system.

In part 2 we will add:

  • Multi enemy that follow player.
  • Target closest enemy to the player.
  • Target only Alive enemy.

Thank you very much!

 

Share:

13 Comments

Add yours
  1. 1
    Vasu

    Hie,
    I tried your tutorial but it did not work.
    I am stuck at [21]InputActionTarget.
    Not able to give the output of “Get all actors of class” to “TargetLockON”
    Please help me, it is kind of urgent

  2. 6
    lewis

    Hey,
    Thanks for the great tutorial – although, I’m really having trouble reading the blueprint image because it is so low quality on send enemy target location. Would you be able to help with what nodes I need?

    Cheers,

  3. 7
    Karo

    Have a problem, the blueprint works and the visual works, but when I toggle the lock on, it locks on to the middle of the map(co-ordinates of the world location I think) and not where the enemy is.

  4. 8
    Nathaniel

    Hi!
    This tutorial looks great but I have a slight problem. At [18] Enemy_BP – Send target location I can´t open the image to see how you did. Could you please explain it to me in writing?

    Thank you in advance, Nathan

  5. 9
    GlaciesD

    So I’m going through this tutorial, and for some reason the TargetVisual does not toggle for me. The camera targets just fine, so the rest of system is functional. The problem seems to be the “Event Target Lock ON” never activating, but I’ve not clue how to deal with that. So if someone could shed a light on it for me, that would be great.

  6. 12
    Marco

    How can we have the visual turn off after we release the target button. Because i want it to turn of based on a press and release function.

+ Leave a Comment