From 7dab87f5eafda68897f7541c859bd18194c5ffff Mon Sep 17 00:00:00 2001 From: marcin Date: Sun, 14 Sep 2025 08:08:41 +0200 Subject: [PATCH] autotargetting fix --- Assets/Scenes/Fight_Arena/Fight_Arena.unity | 16 +++++++++- Assets/Scripts/Characters/AutoTargetting.cs | 33 ++++++--------------- ProjectSettings/ProjectSettings.asset | 6 ++-- 3 files changed, 27 insertions(+), 28 deletions(-) diff --git a/Assets/Scenes/Fight_Arena/Fight_Arena.unity b/Assets/Scenes/Fight_Arena/Fight_Arena.unity index 8b633634b..da47f9fba 100644 --- a/Assets/Scenes/Fight_Arena/Fight_Arena.unity +++ b/Assets/Scenes/Fight_Arena/Fight_Arena.unity @@ -17140,7 +17140,7 @@ PrefabInstance: - target: {fileID: 3749252306457878305, guid: 851e8e61247888340bdec90fc8aa37f5, type: 3} propertyPath: m_AnchoredPosition.x - value: -26.000061 + value: -26.000122 objectReference: {fileID: 0} - target: {fileID: 3806889720075550842, guid: 851e8e61247888340bdec90fc8aa37f5, type: 3} @@ -17547,6 +17547,16 @@ PrefabInstance: propertyPath: m_IsActive value: 1 objectReference: {fileID: 0} + - target: {fileID: 5054440825960491160, guid: 851e8e61247888340bdec90fc8aa37f5, + type: 3} + propertyPath: autoLockOnDistance + value: 2 + objectReference: {fileID: 0} + - target: {fileID: 5054440825960491160, guid: 851e8e61247888340bdec90fc8aa37f5, + type: 3} + propertyPath: unlockDistanceThreshold + value: 3 + objectReference: {fileID: 0} - target: {fileID: 5083365752064418721, guid: 851e8e61247888340bdec90fc8aa37f5, type: 3} propertyPath: m_AnchorMax.x @@ -19414,7 +19424,9 @@ MonoBehaviour: m_sunLight: {fileID: 1976683114} m_moonLight: {fileID: 0} WeatherPresent: 0 + WeatherSystem: {fileID: 0} m_sunLightExists: 1 + m_moonLightExists: 0 --- !u!4 &1013064392 Transform: m_ObjectHideFlags: 10 @@ -22905,6 +22917,8 @@ MonoBehaviour: x: 250 y: 250 z: 250 + m_allFloatingPointFixMembers: [] + m_allWorldSpaceParticleSystems: [] m_originTargetTileX: 0 m_originTargetTileZ: 0 m_terrainUnloadMemoryTreshold: 4294967296 diff --git a/Assets/Scripts/Characters/AutoTargetting.cs b/Assets/Scripts/Characters/AutoTargetting.cs index 1ba3b83d8..9f39177b4 100644 --- a/Assets/Scripts/Characters/AutoTargetting.cs +++ b/Assets/Scripts/Characters/AutoTargetting.cs @@ -169,8 +169,7 @@ namespace Beyond yield return new WaitForSeconds(targetingInterval); } } - - // REFACTORED: This method now has a clearer, more robust flow. + private void UpdateTarget() { if (_playerTransform == null || _gameStateManager == null || _manualSwitchCooldownActive) return; @@ -205,8 +204,7 @@ namespace Beyond // Step 3: Every update, evaluate and apply the correct lock-on state for the current target. UpdateLockOnState(); } - - // NEW: This method exclusively handles the logic for locking on and off. + private void UpdateLockOnState() { if (targetLockSystem == null || _playerTransform == null) return; @@ -216,8 +214,7 @@ namespace Beyond if (CurrentTarget != null && (autoLockSelectedTarget || alwaysLockOnInCombat)) { float distanceToTarget = Vector3.Distance(_playerTransform.position, CurrentTarget.transform.position); - - // This is a hysteresis check: use different distances for locking and unlocking to prevent flickering. + if (targetLockSystem.isLockingOn) { // If already locked, stay locked unless we are beyond the unlock threshold. @@ -233,17 +230,16 @@ namespace Beyond // Synchronize the desired state with the lock-on system. Transform desiredLockTarget = shouldBeLocked ? CurrentTarget.transform : null; - // The lock-on system should be smart enough to not do anything if the target hasn't changed. - // We send the desired target (or null) every update. - targetLockSystem.ManuallySetLockOnTarget(desiredLockTarget, true); + // --- THIS IS THE FIX --- + // We now pass the 'shouldBeLocked' boolean to tell the system whether to lock or unlock. + targetLockSystem.ManuallySetLockOnTarget(desiredLockTarget, shouldBeLocked); if (alwaysLockOnInCombat && desiredLockTarget != null && !targetLockSystem.isLockingOn) { targetLockSystem.SetLockOn(true); } } - - // SIMPLIFIED: This method now only handles changing the CurrentTarget reference and its visual highlight. + private void SetNewTarget(vFSMBehaviourController newTarget, bool forceLockSystemUpdate = false) { if (CurrentTarget == newTarget) return; @@ -309,9 +305,6 @@ namespace Beyond if (targetLockSystem == null) return; _manualSwitchCooldownActive = true; _manualSwitchCooldownTimer = manualSwitchCooldownDuration; - - // After manually unlocking, we let the main UpdateTarget loop find the next best candidate. - // If the previously locked target is still the closest, it will be re-highlighted automatically. } #endregion @@ -347,23 +340,15 @@ namespace Beyond public void ClearTarget(bool findNewOneImmediately) { - // --- FIX APPLIED HERE --- - - // 1. Explicitly tell the lock-on system to unlock immediately. - // This is the crucial step that resets the 'isLockingOn' flag to false. if (targetLockSystem != null) { targetLockSystem.SetLockOn(false); } - - // 2. Deselect the current target and remove its highlight. + SetNewTarget(null); - - // 3. If requested, immediately find a new target. + if (findNewOneImmediately && _gameStateManager != null && _gameStateManager.CurrentState == GameStateManager.State.COMBAT) { - // Now, when UpdateTarget() runs, 'isLockingOn' will be correctly set to false, - // forcing the system to use the stricter 'autoLockOnDistance' for the new candidate. if (!_manualSwitchCooldownActive) { UpdateTarget(); diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index 08a91467c..09474655c 100644 --- a/ProjectSettings/ProjectSettings.asset +++ b/ProjectSettings/ProjectSettings.asset @@ -849,7 +849,7 @@ PlayerSettings: webWasm2023: 0 scriptingDefineSymbols: : UNITY_POST_PROCESSING_STACK_V2 - Android: UNITY_POST_PROCESSING_STACK_V2;CROSS_PLATFORM_INPUT;USE_TIMELINE;USE_NEW_INPUT;PLAYMAKER;PLAYMAKER_1_9;PLAYMAKER_1_9_0;PLAYMAKER_1_8_OR_NEWER;PLAYMAKER_1_8_5_OR_NEWER;PLAYMAKER_1_9_OR_NEWER;TMP_PRESENT;ENEMIES_DISABLED + Android: UNITY_POST_PROCESSING_STACK_V2;CROSS_PLATFORM_INPUT;USE_TIMELINE;USE_NEW_INPUT;PLAYMAKER;PLAYMAKER_1_9;PLAYMAKER_1_9_0;PLAYMAKER_1_8_OR_NEWER;PLAYMAKER_1_8_5_OR_NEWER;PLAYMAKER_1_9_OR_NEWER;TMP_PRESENT;ENEMIES_DISABLED;MOBILE_INPUT CloudRendering: UNITY_POST_PROCESSING_STACK_V2;PLAYMAKER;PLAYMAKER_1_9;PLAYMAKER_1_9_0;PLAYMAKER_1_8_OR_NEWER;PLAYMAKER_1_8_5_OR_NEWER;PLAYMAKER_1_9_OR_NEWER EmbeddedLinux: UNITY_POST_PROCESSING_STACK_V2;PLAYMAKER;PLAYMAKER_1_9;PLAYMAKER_1_9_0;PLAYMAKER_1_8_OR_NEWER;PLAYMAKER_1_8_5_OR_NEWER;PLAYMAKER_1_9_OR_NEWER GameCoreScarlett: UNITY_POST_PROCESSING_STACK_V2;PLAYMAKER;PLAYMAKER_1_9;PLAYMAKER_1_9_0;PLAYMAKER_1_8_OR_NEWER;PLAYMAKER_1_8_5_OR_NEWER;PLAYMAKER_1_9_OR_NEWER @@ -867,9 +867,9 @@ PlayerSettings: Standalone: UNITY_POST_PROCESSING_STACK_V2;CROSS_PLATFORM_INPUT;INVECTOR_BASIC;INVECTOR_MELEE;TOUCH_REACT;GAIA_2_PRESENT;INVECTOR_AI_TEMPLATE;UPPipeline;PLAYMAKER;PLAYMAKER_1_9;PLAYMAKER_1_9_0;PLAYMAKER_1_8_OR_NEWER;PLAYMAKER_1_8_5_OR_NEWER;PLAYMAKER_1_9_OR_NEWER;URP_OUTLINE;ODIN_INSPECTOR;ODIN_INSPECTOR_3;TMP_PRESENT;USE_TIMELINE;ODIN_INSPECTOR_3_1;ODIN_INSPECTOR_3_2;ODIN_INSPECTOR_3_3;ENEMIES_DISABLED VisionOS: UNITY_POST_PROCESSING_STACK_V2;PLAYMAKER;PLAYMAKER_1_9;PLAYMAKER_1_9_0;PLAYMAKER_1_8_OR_NEWER;PLAYMAKER_1_8_5_OR_NEWER;PLAYMAKER_1_9_OR_NEWER WebGL: UNITY_POST_PROCESSING_STACK_V2;PLAYMAKER;PLAYMAKER_1_9;PLAYMAKER_1_9_0;PLAYMAKER_1_8_OR_NEWER;PLAYMAKER_1_8_5_OR_NEWER;PLAYMAKER_1_9_OR_NEWER - Windows Store Apps: UNITY_POST_PROCESSING_STACK_V2;CROSS_PLATFORM_INPUT;PLAYMAKER;PLAYMAKER_1_9;PLAYMAKER_1_9_0;PLAYMAKER_1_8_OR_NEWER;PLAYMAKER_1_8_5_OR_NEWER;PLAYMAKER_1_9_OR_NEWER + Windows Store Apps: UNITY_POST_PROCESSING_STACK_V2;CROSS_PLATFORM_INPUT;PLAYMAKER;PLAYMAKER_1_9;PLAYMAKER_1_9_0;PLAYMAKER_1_8_OR_NEWER;PLAYMAKER_1_8_5_OR_NEWER;PLAYMAKER_1_9_OR_NEWER;MOBILE_INPUT XboxOne: UNITY_POST_PROCESSING_STACK_V2;PLAYMAKER;PLAYMAKER_1_9;PLAYMAKER_1_9_0;PLAYMAKER_1_8_OR_NEWER;PLAYMAKER_1_8_5_OR_NEWER;PLAYMAKER_1_9_OR_NEWER - iPhone: CROSS_PLATFORM_INPUT;INVECTOR_BASIC;INVECTOR_MELEE;GAIA_2_PRESENT;GAIA_PRO_PRESENT;UPPipeline;UNITY_POST_PROCESSING_STACK_V2;TOUCH_REACT;INVECTOR_AI_TEMPLATE;PLAYMAKER;PLAYMAKER_1_9;PLAYMAKER_1_9_0;PLAYMAKER_1_8_OR_NEWER;PLAYMAKER_1_8_5_OR_NEWER;PLAYMAKER_1_9_OR_NEWER;URP_OUTLINE;ODIN_INSPECTOR;ODIN_INSPECTOR_3;TMP_PRESENT;USE_INVECTOR_INVENTORY;USE_TIMELINE;ODIN_INSPECTOR_3_1;ODIN_INSPECTOR_3_2;ODIN_INSPECTOR_3_3;ENEMIES_DISABLED + iPhone: CROSS_PLATFORM_INPUT;INVECTOR_BASIC;INVECTOR_MELEE;GAIA_2_PRESENT;GAIA_PRO_PRESENT;UPPipeline;UNITY_POST_PROCESSING_STACK_V2;TOUCH_REACT;INVECTOR_AI_TEMPLATE;PLAYMAKER;PLAYMAKER_1_9;PLAYMAKER_1_9_0;PLAYMAKER_1_8_OR_NEWER;PLAYMAKER_1_8_5_OR_NEWER;PLAYMAKER_1_9_OR_NEWER;URP_OUTLINE;ODIN_INSPECTOR;ODIN_INSPECTOR_3;TMP_PRESENT;USE_INVECTOR_INVENTORY;USE_TIMELINE;ODIN_INSPECTOR_3_1;ODIN_INSPECTOR_3_2;ODIN_INSPECTOR_3_3;ENEMIES_DISABLED;MOBILE_INPUT tvOS: UNITY_POST_PROCESSING_STACK_V2;PLAYMAKER;PLAYMAKER_1_9;PLAYMAKER_1_9_0;PLAYMAKER_1_8_OR_NEWER;PLAYMAKER_1_8_5_OR_NEWER;PLAYMAKER_1_9_OR_NEWER additionalCompilerArguments: {} platformArchitecture: {}