Lock-On Targeting
Lock On Target Settings
All the parameters governing lock-on targeting reside within the "Lock On Target Settings" section of your Camera Mode. Let's explore each setting and its impact on camera behavior:
Target Management:
bResetTargetOnChangeCameraMode
: Automatic Reset: When enabled, the target is automatically released when you switch to a different camera mode. This ensures a clean transition and prevents the camera from unexpectedly following a target in a new mode.
Rotation Behavior:
RotateCameraByYaw
: Yaw Tracking: Dictates whether the camera rotates horizontally (in yaw) to track the target's position.RotateCameraByPitch
: Pitch Tracking: Determines whether the camera rotates vertically (in pitch) to track the target.
Interpolation:
CameraRotationInterpolation
: Smoothness of Tracking: This setting controls how smoothly the camera rotates towards the target. You can adjust the interpolation method (Smooth or Constant) and speed to achieve the desired level of responsiveness.bResetInterpolationSpeedAfterChangeTarget
: Reset on Target Change: When enabled, the interpolation speed is reset to its initial value whenever a new target is locked onto. This prevents sudden jumps when switching between targets.
Rotation Limits:
bClampByCameraModeRotationLimits
: Respecting View Limits: When enabled, the camera's rotation while tracking a target is restricted by the pitch and yaw limits defined in the Camera Mode's Rotation Settings. This prevents the camera from moving outside its intended boundaries.
Distance Limits:
bUseMaxLockDistance
: Enable Distance Limit: Activates a maximum distance constraint for lock-on targeting.bResetTargetOnReachMaxDistance
: Auto-Reset on Distance: When enabled, the target is automatically released if it moves beyond the maximum lock distance.MaxLockDistance
: Maximum Tracking Distance: Defines the maximum distance (in Unreal Units) at which the camera can lock onto and track a target.
Visibility Checks:
bUseCheckTargetVisibility
: Line of Sight Tracking: Activates line trace checks to ensure the target remains visible to the camera.bResetLockOnLostVisibleTarget
: Auto-Reset on Obscured Target: If enabled, the lock is automatically released if the target becomes obstructed and is no longer in the camera's line of sight.CheckVisibilityTraceChannel
: Trace Channel: Specifies the collision channel used for line traces when checking target visibility.
Player Input Behavior:
bHardLockOnTarget
: Forceful Tracking: When enabled, player input is completely ignored, and the camera is forcefully locked onto the target. This creates a strict and unwavering focus on the target.bPauseLockAfterPlayerInput
: Temporary Pause: If enabled (and bHardLockOnTarget is false), the lock is briefly paused after the player provides camera input. This allows the player to make minor adjustments without fully releasing the lock.PauseLockAfterPlayerInputTime
: Pause Duration: Specifies the duration (in seconds) for which the lock is paused after player input.bResetTargetAfterPlayerInput
: Unlock with Input: When enabled (and bHardLockOnTarget is false), the target is completely released after a certain amount of accumulated player input. This allows the player to break the lock by intentionally moving the camera away from the target.RequiredPlayerInputForResetTarget
: Input Threshold: Defines the amount of player input (in degrees, for both yaw and pitch) required to trigger a target reset.ResetAccumulatedPlayerInputForResetTargetDelay
: Input Reset Delay: Sets the delay (in seconds) after which accumulated player input is reset if no further input is provided.
Cone Aiming:
bUseDesiredConeRotation
: Approximate Targeting: Enables aiming within an approximate cone around the target's location. This provides a more forgiving lock-on experience, as the camera doesn't need to be perfectly aligned with the target.DeisredConeRotationYaw
: Cone Size: Determines the yaw angle (in degrees) of the aiming cone. A larger angle creates a wider cone, giving the player more freedom of movement while maintaining the lock.
User Functions for Control
To manage lock-on targeting during gameplay, use the ATPCCameraLockOnTargetObject object, which is accessible through the GetCameraLockOnTargetObject
function of your ATPCCameraComponent.
Key Functions:
SetTargetActor
: Attempts to lock onto the specified actor, considering visibility and distance constraints. Returns true if the lock is successfully established.GetTargetActor
: Returns a pointer to the currently locked actor. If no target is set, it returns nullptr.
Additional Functions (For Advanced Scenarios):
CanSetActorAsTarget
: Checks if the specified actor is a valid target, considering visibility and distance limits. This can be useful for filtering potential targets before attempting to lock on.GetDistanceSquareToActor
: Returns the squared distance between the camera owner and the specified actor. This allows you to efficiently calculate distances for custom targeting logic.IsActorVisible
: Checks if the specified actor is visible from the camera's perspective using line traces. You can use this function to implement custom visibility checks beyond the plugin's built-in functionality.IsValidDistanceToActor
: Checks if the specified actor is within the maximum lock distance defined in the Camera Mode settings
Targeting Specific Parts of an Actor
By default, the camera will aim at the target actor's origin (its world location). However, you can customize this behavior to target a specific part of the actor.
Using the ATPCLockOnTargetLocationComponent
Add Component: Attach an
ATPCLockOnTargetLocationComponent
to the desired part of your target actor (e.g., the head for a character).Adjust Position: If needed, adjust the relative location of the
ATPCLockOnTargetLocationComponent
within the actor to fine-tune the targeting point.Automatic Targeting: When you lock onto this actor using
SetTargetActor
, the camera will now aim at the location of theATPCLockOnTargetLocationComponent
.
Debugging Lock-On Behavior
The plugin offers debug options to visualize and troubleshoot your lock-on setup:
Enable Lock On Target Debug: In the
DebugRules
structure of yourATPCCameraComponent
, setbEnableLockOnTargetDebug
to true. This prints debug information about the lock-on system to the screen and output log.Visualize Aiming Cone: When
bUseDesiredConeRotation
is enabled, and debug mode is active, the plugin draws a visual representation of the aiming cone in the game world, helping you understand its size and position.
Last updated