Third Person Action RPG Lock On Question - Distance Lock Off Bug

Sorry for such a long post, but there is a lot to unpack and I tend to be confusing.

TLDR; I am currently working on a third person lock on system similar to Dark Souls, Trials of Mana, For Honor etc. Camera doesn’t unlock when the Player moves away from the Target.

Pictures of the blueprint are in their respective descriptions and video explanation is at the bottom.

The bug:

When the Player moves away from the Target the Lock On System properly unlocks the camera for a brief moment and disables targeting. Then, after a few seconds, the camera becomes partially locked to the same Target. I mean partially because yaw input is active, but pitch isn’t.

The Blueprint:

Input Action:

The blueprint starts with an input action that flip flops two custom events; Find Target and Disable Targeting. Input Action - Find Target and Disable Targeting Functions - Imgur

Find Target Custom Event:

First, the system clears all the available targets in the array (which is set later). Then it does a 10 meter sphere trace around the player for any World Dynamic or Pawn classes. Find Target Custom Event - Imgur

Next, is a sphere trace check of all the World Dynamic or Pawns if they have the Enemy Interface. If it does, then it casts a line trace from the player to those objects. If something breaks the line trace then it does nothing. If something doesn’t break the line trace, then it adds those objects to the All Available Targets array to be used later. Enemy Interface Check - Imgur I should note the “Check Actor Collision” node is the collapsed vector math and line trace components.

I am not sure if this next check is 100% necessary… After adding all of the possible targets to the array, the system double checks to see if the array list is at least 1. If it is, then it continues with the targeting. If it isn’t, then it disables targeting. More on this in a moment. Imgur: The magic of the Internet

The system chooses the nearest Target. This is done by getting the distances of all the targets in the All Available Targets array then compares that to the Player’s location. Once this is finished finding the nearest target, the system sets the Nearest Target variable. Choose Nearest Target Function - Imgur


Then, the IsTargeting and Rotation To Target booleans are set to true and the third person character rotates to the Nearest Target with the Smooth Rotation To Target custom event. Imgur: The magic of the Internet Smooth Rotation custom event Imgur: The magic of the Internet

When the Rotation to Target is set to true, it triggers an OnTick event that rotates the Third Person Character around the Target. On Tick Rotation - Imgur Target Rotation float is the location math.

Camera Lock Toggle

After all that is handled, we finally get to the issue. The system sends the IsTargeting boolean to the Enemy with a Blueprint Interface message, which turns on and off the targeting indicator. The timeline is how often the Break Sightline and Distance Fall off custom events occur (every 0.2 seconds). This is easier to use than OnTick in my opinion as it’s right with the rest of the code. Timeline, Sightline, Distance lock off, and BPI Message - Imgur

Camera Look At Function

Vector and rotator math for the camera to follow the target. Camera Look At Target Function - Imgur While this is active, the normal camera input is deactivated. Camera Input Imgur: The magic of the Internet

Break Sightline

This little bit sends a line trace to only the Nearest Target. If something breaks the line trace (i.e. a wall), then the targeting is disabled with the Disable Targeting Custom event. More on that later. Imgur: The magic of the Internet This is working as intended.

Distance Lock Off

This is the part that isn’t working as intended. When the player moves out of the targeting radius, the targeting and the camera rotation should be disabled. However, for reasons I can’t figure out, the Timeline (from the camera lock toggle picture Timeline, Sightline, Distance lock off, and BPI Message - Imgur) still activates the Break Sightline and Distance Lock Off Custom Events which activates the Camera Look At Function.

Disable Targeting

When the conditions are met (moving away from the target, the target is killed, the input action is activated, etc.) then targeting should be disabled. Disable Targeting - Imgur In case of bug targeting is canceled, but the camera rotation isn’t.

Video Description

I am happy to clarify if I am spouting nonsense or if my Blueprint is weird/has unnecessary parts. Thank you in advance for taking a look.

Credit to ZzGERTzZ on the Unreal Engine Marketplace and Rayziyun for the basis of my blueprint.

I’ve had a brief look at this. The one thing I’d change is the flip flop. Bascically I’ve found MANY times, you can’t rely on FlipFlop to do what you think it ought to, especially where ticked logic is involved.

I’d recommend changing it to:

EDIT: 2nd attempt at describing this. FlipFlop is not state dependent, your code is. Somehow, the flip flop is getting out of step with the state of your code. The upshot of this is half your code think it’s locked when the other half thinks it’s unlocked. And that’s what you’re experiencing…

This helped fix part of the issue; flipping between locked and unlocked with multiple button presses after moving away from the target. However, the Timeline still runs the bit of Blueprinting that holds the Distance Lock Off and the Break Sightline custom events. So, the partial camera locking bug still appears.

Would I have performance issues if there was a branch “IsTargeting” check after the Timeline? Basically checking a variable (almost) on tick.

Edit: I forgot to mention, thank you for replying. I didn’t get back to this for a while as I have been pretty busy with college graduation.

Edit 2: Clarity and Grammar

This is how I enter my lock on function:


ToggleWeapon is the keyboard action to try a lock-on. ForceLockonToggle is a custom event that will fire when something happens to force you toggle your lockon. This can happen, like in your case, if you are too far away from your target or if you are blocked by LoS or if your target dies or is removed. It sets your weapon active state to the opposite of its current state, then goes down the branch to see if it should turn it on or off.

Here is my disable lock-on function:

That custom event could be called on a check that happens every tick, every few ticks, etc. You can change the tick rate of an actor manually as well, if you are worried about performance, but I’ve yet to see any kind of performance dip at all, so I haven’t tried using anything like a timeline for that. It is useful though for the sake of game feel, if you broke LoS for only one tick and it unlocked it would be pretty annoying. I split my tick into two branches, one for calculations done while locked on and one for calculations done while not locked on. I haven’t really touched this project in a bit so it is kinda messy, apologies for that

Unfortunately, your pictures aren’t loading.