LOCK-ON TARGETING SYSTEM
Documentation
INDEX
INTRODUCTION
This project has been mainly influenced by Demon's Souls, Dark Souls, Bloodborne and other souls-like games with a lock-on camera system.
The Lock-on Targeting System uses mathematical concepts to create an efficient targeting system, which can be used with a gamepad, keyboard and mouse.
IMPLEMENTATION: USING LTS AS A BASE PROJECT
You can use Lock-on Targeting System (LTS) as a base/template for your project. To do this, simply download the complete project through your Unreal Engine 4 library, start it and check its operating.
IMPLEMENTATION: USING LTS IN YOUR PROJECT
You can consult this video to watch the Lock-on Targeting System installation tutorial, or follow the steps bellow. If after reading (or watching) you have any questions, please feel free to ask in our discord community.
STEPS
1.
Open your project;
2.
Go to Edit → Project Settings → Input, add the action mapping bellow:
3.
Make sure that you have all these input events.
You can, of course, use the keys you want. In this example I used the keys i, j, k and l to swap the target (weird, I know, but just for testing purposes). Do not worry about adding the mouse here, we will not use an action mapping for the mouse, below you will see when the mouse will be implemented.
4.
Open up the Lock-on Targeting System Project;
5.
In the Lock-on Targeting System Project, inside the content folder, right click in “LockOnTS” folder, then click “migrate”;
6.
Find your project folder, then select the content folder. The LTS will be migrated;
7.
After migration, go back to your project. Go to your character’s blueprint and add the “LockOnComponent” component;
8.
Drag and drop the LockOnComponent in the blueprint. With this “get”, call the “Initialization” function. Plug it on the Event Begin Play. Connect the indicated components.
In "Bone to Lock On Widget", enter the name of the bone in a position you would like the reticle widget to be. Be sure to enter the exact bone name, as it is case sensitive. This is an interesting tool, because it gives you the freedom to place your aim anywhere on the enemy. For example, if your character is going to fight a giant, the aim may simply be at the giant's foot!
If you don't know how to check the name of your character's skeleton bones, click on this video and see how to do it at 4min and 54s.
You can correct the height in relation to this bone. In this example I put "head". As the reticle would be a little high, I discounted about 30cm in height, so the value -30 was inserted (from the bone down is negative; from the bone up it is positive).
8.
Drag and drop the LockOnComponent in the blueprint. With this “get”, call the “LockOn” function. Call the “LockOn” action event (created in the action mappings). Make the connections below:
9.
In yours functions that control the character's camera (in the case of Epic's ThirdPersonTemplate called "TurnRate" and "LookUpRate" for the gamepad, "Turn" and LookUp "for the mouse), connect the functions "AxisTurn" and "Axis LookUp" from LockOnComponent. These functions allow you to reduce camera movement if you choose to enable camera movement when lock-on is active. You can see how do to this in this video at 3min and 15s. The configuration will be as below:
10.
Now, a crucial part for the lock-on to work correctly: the interface implementation. It is very simple and quick to add.
Click on "Class Settings" on the top bar. In the "details" tab, look for "interfaces" and click "Add". Add the "TargetInformationsInterface" interface.
11.
After adding the interface, a new function will be available on your character's blueprint. Check the "interfaces" tab below the "functions" tab.
The "TargetInformations" function will be available for implementation. Open it and simply add the Lock-on Component to the return part of the function.
12.
Everything is properly configured and you can now use the Lock-on Targeting System!
Remember that this component and interface must also be added to the classes you want to target. For example, if your enemy is not in the same class as yours (for example ThirdPersonCharacter), add the Lock-on Component on this enemy and also the interface, following all these steps (except steps 8 and 9). In this case, for example, my enemy is also of the "ThirdPersonTemplate" class, so, as I already added the component and the interface, everything is properly arranged to work!
"How can I report that an enemy has died?"
When you are fighting an enemy and this enemy dies, just call on the enemy's blueprint (in any event that you created for the character's "death"), the following node:
Drag the LockOnComponent and call the "Death Event". Please, make sure if you're using the "destroy actor" function, put a delay (any time delay) after the Death Event above, but before the "Destroy Actor" function, like the image below.
This node will inform the Lock-on Targeting System that the enemy has died (being able to automatically switch the target to another enemy, if you have marked the variable "SwapTargetWhenTheCurrentDies?" as true) and also to inform the system that the target that died cannot be "targeted" anymore.
REVIEW________________________________________
Hey,
First of all, thanks for your interest in Lock-on Targeting System.
If you purchased Lock-on Targeting System: thank you very much!
If you have any questions, feel free to send it on the product page or via email (available on the author page).
Please consider writing a review on the marketplace page (link), each review helps me a lot as a developer!
QUICK SETTINGS: CUSTOMIZATION OPTIONS
The Lock-on Targeting System has several customization options. Take your time and check out its features! All variables are commented with a "tooltip" (just hover over the variable). All functions have comments detailing their operation.
COMMENTING ON SOME DETAILS
Click to expand
- HOW IT WORKS
When activating the lock-on (in the template project, pressing tab, middle button mouse or the gamepad right thumbstick button), the system initially searches for the closest enemy to the center of the screen. The "LockOnCenterTolerance" variable defines precision, that is, it defines how close to the center of the screen the target must be for this algorithm to capture the target.
If there is no enemy close to the center, the system searches for the nearest enemy in the sphere radius.
For a target to be considered an "enemy", it must have the "TargetInformationsInterface" interface and have the "isTarget?" boolean variable marked as true. It is worth mentioning that the lock-on ignores the character itself, so don't worry about selecting yourself.
- DYNAMIC TARGET SWAP
The target swap can be done using keyboard (keys selected by the user - default keys: i, j, k and L -- weird I know, but just for testing), mouse (mouse up, down, left and right) and gamepad (using the right thumbstick axis). You can change the target swap mouse sensitivity in “SwapTargetMouseSensitivity” variable (in my tests I used ~2500DPI mouse for the default value).
When an target is locked-on, the swap occur in relation to the angle of enemy in relation to the player, that is: a part of the target that points towards the player corresponds to the angle of 0º / "- 0º", his left at 90º , his back at 180º / -180º, his right at -90º. Thus, it is possible to move out of the enemy swap pattern from left to right and vice versa to also switch between targets ahead and targets behind the currently selected target (you can see this angles in the 3 images below).
- LOCK-ON DISTANCE
You can change the lock-on distance by changing the value of the “MaximumLockOnDistance” variable (the default lock-on distance is 2500).This lock-on distance determines the distance the lock-on can be activated and when it is disabled (if the “CheckEnemyDistance?” variable is marked as true).
- OBSTACLES DETECTION
The lock-on targeting system also has obstacle detection between the player and the enemy: if there are any obstacles, the lock-on is automatically disabled. But you can turn this system off by checking the "IgnoreObstaclesWhenLockedOn?" as true. You can also combine this option with the "LockOnThroughObstacles" variable, which allows you to lock-on a target through obstacles.
- LOOK AT THE ENEMY (CHARACTER ROTATION)
You can enable the function of always looking at the enemy, that is, not only does the camera rotate towards the enemy, but also the character. By default, this option is disabled, but to activate it, just check the boolean variable “LookAtTheTargetWhenLockedOn” as true (or press "N" on the template project).
- FREE LOOK UP AXIS/BLOCK LOOK TURN AXIS
You can activate the option to make the look up axis free. This means that even though the lock-on is activated, you can move the camera freely on the look up axis. This can be done by marking the boolean variable “FreeLookUpAxis?” as true. By default, this variable is marked as false. You can also make the Look Turn Axis move by checking the "BlockTurnAxis?" as false.
- SWAP TARGET WHEN THE CURRENT DIES
It is possible to enable automatic target swap when the current target dies. To do this, simply change the boolean variable “SwapTargetWhenTheCurrentDies?” to true or false. By default the variable is marked as true. When you are fighting an enemy and he dies, just call on the enemy's blueprint (in any event that you created for the character's "death"), the two nodes from installation tutorial step 12.
More descriptions coming soon. For now, all variables and functions are commented out in Lock-on Targeting System.
UPDATES
LOG
09/28/2020: Update 2.0 released!
Support to Unreal Engine 4.17, 4.18, 4.19, 4.20, 4.21, 4.22, 4.23, 4.24, 4.25;
Works with multiplayer;
Now everything is included in a single "component", that is, you can use the lock-on targeting system on any character easily, just inserting the "Lock-on Component";
New reticles added;
Choose whether a character with the Lock-on Component is a target or not;
Option to activate lock-on through obstacles and option to ignore obstacles when lock-on is active;
Option to turn off the distance checker;
Now it is possible to keep mouse and keyboard (both) active to swap the target.
OTHER TUTORIALS - V3.0 (UE 4.24, 4.25, 4.26, 4.27 and 5.0)
Setup Guide (Subtitled)
Integration with Advanced Locomotion System V4 (ALSV4, Subtitled)
Customizing the lock-on reticle
Look at the target
Free Axes
Lock-on through walls and/or ignore obstacles when locked-on
Maximum Lock-on Distance
Distance Checker
Lock-on Type - Centered First vs. Nearest First
Automatic Target Swap