Implement automatic retargeting or clearing of active runtime target

This commit is contained in:
2026-04-25 17:26:17 +02:00
parent d9f724c45d
commit d2f2b38f34

View File

@@ -886,6 +886,8 @@ export class RuntimeHost {
this.resolveThirdPersonTargetAssist(),
handleRuntimeTargetLookInput: (input) =>
this.handleRuntimeTargetLookInput(input),
handleRuntimeTargetLookBoundaryReached: () =>
this.retargetOrClearActiveRuntimeTarget(),
isCameraDrivenExternally: () =>
this.resolveActiveRuntimeCameraRig() !== null ||
this.resolveDialogueAttentionNpc() !== null,
@@ -5851,6 +5853,30 @@ export class RuntimeHost {
return bestCandidate;
}
private retargetOrClearActiveRuntimeTarget(): boolean {
if (this.activeRuntimeTargetReference === null) {
return false;
}
const replacementTarget =
this.resolveRuntimeTargetCandidateNearestScreenCenter({
exclude: this.activeRuntimeTargetReference,
maxDistanceFromPlayer: TARGETING_AUTO_RETARGET_SAFE_DISTANCE
});
if (replacementTarget !== null) {
this.setActiveRuntimeTargetReference({
kind: replacementTarget.kind,
entityId: replacementTarget.entityId
});
this.proposedRuntimeTarget = replacementTarget;
return true;
}
this.setActiveRuntimeTargetReference(null);
return false;
}
private updateActiveRuntimeTargetLockState() {
if (
this.activeRuntimeTargetReference === null ||
@@ -5873,22 +5899,7 @@ export class RuntimeHost {
activeTarget.center
) > TARGETING_ACTIVE_TARGET_RELEASE_DISTANCE
) {
const replacementTarget =
this.resolveRuntimeTargetCandidateNearestScreenCenter({
exclude: this.activeRuntimeTargetReference,
maxDistanceFromPlayer: TARGETING_AUTO_RETARGET_SAFE_DISTANCE
});
if (replacementTarget !== null) {
this.setActiveRuntimeTargetReference({
kind: replacementTarget.kind,
entityId: replacementTarget.entityId
});
this.proposedRuntimeTarget = replacementTarget;
return;
}
this.setActiveRuntimeTargetReference(null);
this.retargetOrClearActiveRuntimeTarget();
return;
}
}