From 328e8dea0ac60f2030990e82b3bf0da6c7b17918 Mon Sep 17 00:00:00 2001 From: Michal Pikulski Date: Tue, 7 Oct 2025 09:42:59 +0200 Subject: [PATCH] Finalize normalized movement settings --- .../Scenes/MiniGames/DivingForPictures.unity | 136 ++++-------------- .../Obstacles/FloatingObstacle.cs | 7 +- .../Tiles/TrenchTileSpawner.cs | 7 +- Assets/Scripts/Utils/AppleHillsUtils.cs | 41 +++++- Assets/Settings/DivingMinigameSettings.asset | 6 +- 5 files changed, 75 insertions(+), 122 deletions(-) diff --git a/Assets/Scenes/MiniGames/DivingForPictures.unity b/Assets/Scenes/MiniGames/DivingForPictures.unity index 47b91859..8f8075b6 100644 --- a/Assets/Scenes/MiniGames/DivingForPictures.unity +++ b/Assets/Scenes/MiniGames/DivingForPictures.unity @@ -314,6 +314,8 @@ LineRenderer: m_RayTracingAccelStructBuildFlagsOverride: 0 m_RayTracingAccelStructBuildFlags: 1 m_SmallMeshCulling: 1 + m_ForceMeshLod: -1 + m_MeshLodSelectionBias: 0 m_RenderingLayerMask: 1 m_RendererPriority: 0 m_Materials: @@ -335,6 +337,7 @@ LineRenderer: m_AutoUVMaxDistance: 0.5 m_AutoUVMaxAngle: 89 m_LightmapParameters: {fileID: 0} + m_GlobalIlluminationMeshLod: 0 m_SortingLayerID: 0 m_SortingLayer: 0 m_SortingOrder: 0 @@ -569,19 +572,6 @@ MonoBehaviour: m_EditorClassIdentifier: obstaclePrefabs: - {fileID: 4743746373562280435, guid: 315a624eb99600444a51bb1d37c51742, type: 3} - spawnInterval: 2 - spawnIntervalVariation: 1 - maxSpawnAttempts: 10 - spawnCollisionRadius: 1 - minMoveSpeed: 2 - maxMoveSpeed: 4 - useObjectPooling: 1 - maxPerPrefabPoolSize: 15 - totalMaxPoolSize: 30 - tileLayerMask: - serializedVersion: 2 - m_Bits: 576 - obstacleLayer: 11 onObstacleSpawned: m_PersistentCalls: m_Calls: [] @@ -637,20 +627,10 @@ MonoBehaviour: - {fileID: 8588568014006713718, guid: 7c45910be7187144b8d2af12ff772353, type: 3} - {fileID: 2665121316138540107, guid: c0d4b6d8a3b9a2447b883a78c568826c, type: 3} - {fileID: 827631101927032693, guid: 5d23561cb618e86409a2b7ccbf08e37d, type: 3} - baseSpawnProbability: 0.2 - maxSpawnProbability: 0.5 - probabilityIncreaseRate: 0.01 - guaranteedSpawnTime: 10 - spawnCooldown: 5 - basePoints: 10 - depthMultiplier: 2 playerRopes: - {fileID: 1435210811} - {fileID: 1062017697} - {fileID: 173052728} - speedTransitionDuration: 2 - surfacingSpeedFactor: 3 - surfacingSpawnDelay: 3 surfacingTimeline: {fileID: 2064311130} --- !u!4 &424805726 Transform: @@ -705,6 +685,8 @@ SpriteRenderer: m_RayTracingAccelStructBuildFlagsOverride: 0 m_RayTracingAccelStructBuildFlags: 1 m_SmallMeshCulling: 1 + m_ForceMeshLod: -1 + m_MeshLodSelectionBias: 0 m_RenderingLayerMask: 1 m_RendererPriority: 0 m_Materials: @@ -726,6 +708,7 @@ SpriteRenderer: m_AutoUVMaxDistance: 0.5 m_AutoUVMaxAngle: 89 m_LightmapParameters: {fileID: 0} + m_GlobalIlluminationMeshLod: 0 m_SortingLayerID: 622133659 m_SortingLayer: -1 m_SortingOrder: 0 @@ -829,6 +812,8 @@ SpriteRenderer: m_RayTracingAccelStructBuildFlagsOverride: 0 m_RayTracingAccelStructBuildFlags: 1 m_SmallMeshCulling: 1 + m_ForceMeshLod: -1 + m_MeshLodSelectionBias: 0 m_RenderingLayerMask: 1 m_RendererPriority: 0 m_Materials: @@ -850,6 +835,7 @@ SpriteRenderer: m_AutoUVMaxDistance: 0.5 m_AutoUVMaxAngle: 89 m_LightmapParameters: {fileID: 0} + m_GlobalIlluminationMeshLod: 0 m_SortingLayerID: 0 m_SortingLayer: 0 m_SortingOrder: 0 @@ -916,8 +902,6 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: d39dbaae819c4a128a11ca60fbbc98c9, type: 3} m_Name: m_EditorClassIdentifier: - tapMaxDistance: 0.05 - tapDecelerationRate: 5 --- !u!114 &747976399 MonoBehaviour: m_ObjectHideFlags: 0 @@ -930,14 +914,6 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 9072050a53fc4b539f4f4716bab53c07, type: 3} m_Name: m_EditorClassIdentifier: - wobbleFrequency: 1.5 - baseWobbleAmplitude: 8 - speedToAmplitude: 2 - maxRotationLimit: 45 - verticalFrequency: 0.5 - verticalAmplitude: 0.2 - velocitySmoothing: 10 - rotationSmoothing: 10 --- !u!114 &747976400 MonoBehaviour: m_ObjectHideFlags: 0 @@ -950,41 +926,8 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 8222f0e3aeeb4fc4975aaead6cf7afbe, type: 3} m_Name: m_EditorClassIdentifier: - damageImmunityDuration: 1 - obstacleLayerMask: - serializedVersion: 2 - m_Bits: 64 - blockInputDuringImmunity: 0 playerCharacter: {fileID: 747976396} playerController: {fileID: 747976398} - bumpMode: 0 - bumpForce: 5 - smoothMoveSpeed: 8 - bumpCurve: - serializedVersion: 2 - m_Curve: - - serializedVersion: 3 - time: 0 - value: 0 - inSlope: 0 - outSlope: 2 - tangentMode: 0 - weightedMode: 0 - inWeight: 0 - outWeight: 0 - - serializedVersion: 3 - time: 1 - value: 1 - inSlope: 0 - outSlope: 0 - tangentMode: 0 - weightedMode: 0 - inWeight: 0 - outWeight: 0 - m_PreInfinity: 2 - m_PostInfinity: 2 - m_RotationOrder: 4 - blockInputDuringBump: 1 --- !u!114 &747976401 MonoBehaviour: m_ObjectHideFlags: 0 @@ -997,11 +940,6 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: c9c18dbd013d42ae8c221e6205e4d49c, type: 3} m_Name: m_EditorClassIdentifier: - damageImmunityDuration: 1 - obstacleLayerMask: - serializedVersion: 2 - m_Bits: 2048 - blockInputDuringImmunity: 0 playerCharacter: {fileID: 747976396} playerController: {fileID: 747976398} --- !u!60 &747976402 @@ -1109,9 +1047,6 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: d8ea29cc80524de8affe17b930cd75c1, type: 3} m_Name: m_EditorClassIdentifier: - damageBlinkColor: {r: 1, g: 0, b: 0, a: 1} - blinkRate: 0.15 - damageColorAlpha: 0.7 targetSpriteRenderer: {fileID: 730962734} --- !u!95 &747976405 Animator: @@ -1250,20 +1185,6 @@ MonoBehaviour: - {fileID: 8773148034285304506, guid: cba81aa25acbe564cb363782f87c988a, type: 3} - {fileID: -5093844878195686178, guid: eb62213ffae1fa242bcf16e696d9324f, type: 3} - {fileID: 8944853044452083345, guid: 4ad95f797558b28478685ca60bd90ff4, type: 3} - spawnInterval: 0.5 - speedRange: {x: 0.5, y: 2} - scaleRange: {x: 0.8, y: 1.2} - wobbleSpeedRange: {x: 0.2, y: 1} - wobbleAmountRange: {x: 0.05, y: 0.15} - spawnXMin: -3.5 - spawnXMax: 3.5 - spawnY: -6.78 - wobbleMinScale: 0.5 - wobbleMaxScale: 1.2 - useObjectPooling: 1 - initialPoolSize: 10 - maxPoolSize: 30 - surfacingSpeedFactor: 0.5 --- !u!4 &1003335105 Transform: m_ObjectHideFlags: 0 @@ -1356,6 +1277,8 @@ LineRenderer: m_RayTracingAccelStructBuildFlagsOverride: 0 m_RayTracingAccelStructBuildFlags: 1 m_SmallMeshCulling: 1 + m_ForceMeshLod: -1 + m_MeshLodSelectionBias: 0 m_RenderingLayerMask: 1 m_RendererPriority: 0 m_Materials: @@ -1377,6 +1300,7 @@ LineRenderer: m_AutoUVMaxDistance: 0.5 m_AutoUVMaxAngle: 89 m_LightmapParameters: {fileID: 0} + m_GlobalIlluminationMeshLod: 0 m_SortingLayerID: 0 m_SortingLayer: 0 m_SortingOrder: 0 @@ -1644,7 +1568,6 @@ MonoBehaviour: m_ScreenCoordScaleBias: {x: 0, y: 0, z: 0, w: 0} m_RequiresDepthTexture: 0 m_RequiresColorTexture: 0 - m_Version: 2 m_TaaSettings: m_Quality: 3 m_FrameInfluence: 0.1 @@ -1652,6 +1575,7 @@ MonoBehaviour: m_MipBias: 0 m_VarianceClampScale: 0.9 m_ContrastAdaptiveSharpening: 0 + m_Version: 2 --- !u!1 &1224833348 GameObject: m_ObjectHideFlags: 0 @@ -1684,11 +1608,11 @@ RectTransform: m_Children: [] m_Father: {fileID: 116234201} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_AnchorMin: {x: 1, y: 1} - m_AnchorMax: {x: 1, y: 1} - m_AnchoredPosition: {x: -81, y: -76} - m_SizeDelta: {x: 245.4807, y: 78.4255} - m_Pivot: {x: 1, y: 1} + m_AnchorMin: {x: 0, y: 1} + m_AnchorMax: {x: 0, y: 1} + m_AnchoredPosition: {x: 200, y: -43} + m_SizeDelta: {x: 245.48071, y: 78.4255} + m_Pivot: {x: 0, y: 1} --- !u!114 &1224833350 MonoBehaviour: m_ObjectHideFlags: 0 @@ -1896,6 +1820,8 @@ LineRenderer: m_RayTracingAccelStructBuildFlagsOverride: 0 m_RayTracingAccelStructBuildFlags: 1 m_SmallMeshCulling: 1 + m_ForceMeshLod: -1 + m_MeshLodSelectionBias: 0 m_RenderingLayerMask: 1 m_RendererPriority: 0 m_Materials: @@ -1917,6 +1843,7 @@ LineRenderer: m_AutoUVMaxDistance: 0.5 m_AutoUVMaxAngle: 89 m_LightmapParameters: {fileID: 0} + m_GlobalIlluminationMeshLod: 0 m_SortingLayerID: 0 m_SortingLayer: 0 m_SortingOrder: 0 @@ -2073,22 +2000,12 @@ MonoBehaviour: - {fileID: 2956826569642009690, guid: 43ed47cbe958b9f46b462e2fca2382c5, type: 3} - {fileID: 2956826569642009690, guid: 4f772f2aebd38b44ca31063d196c77c1, type: 3} - {fileID: 2956826569642009690, guid: 7f7f10ca24a5afe46be797daea64111a, type: 3} - initialTileCount: 3 - tileSpawnBuffer: 1 - moveSpeed: 5 - speedUpFactor: 0 - speedUpInterval: 0 - maxMoveSpeed: 12 - useObjectPooling: 1 - maxPerPrefabPoolSize: 3 - totalMaxPoolSize: 25 onTileSpawned: m_PersistentCalls: m_Calls: [] onTileDestroyed: m_PersistentCalls: m_Calls: [] - velocityCalculationInterval: 0.5 onLastTileLeft: m_PersistentCalls: m_Calls: [] @@ -2144,6 +2061,8 @@ SpriteRenderer: m_RayTracingAccelStructBuildFlagsOverride: 0 m_RayTracingAccelStructBuildFlags: 1 m_SmallMeshCulling: 1 + m_ForceMeshLod: -1 + m_MeshLodSelectionBias: 0 m_RenderingLayerMask: 1 m_RendererPriority: 0 m_Materials: @@ -2165,6 +2084,7 @@ SpriteRenderer: m_AutoUVMaxDistance: 0.5 m_AutoUVMaxAngle: 89 m_LightmapParameters: {fileID: 0} + m_GlobalIlluminationMeshLod: 0 m_SortingLayerID: 0 m_SortingLayer: 0 m_SortingOrder: 0 @@ -2365,14 +2285,6 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 9072050a53fc4b539f4f4716bab53c07, type: 3} m_Name: m_EditorClassIdentifier: - wobbleFrequency: 1.5 - baseWobbleAmplitude: 8 - speedToAmplitude: 2 - maxRotationLimit: 45 - verticalFrequency: 0.5 - verticalAmplitude: 0.5 - velocitySmoothing: 10 - rotationSmoothing: 10 --- !u!1660057539 &9223372036854775807 SceneRoots: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Minigames/DivingForPictures/Obstacles/FloatingObstacle.cs b/Assets/Scripts/Minigames/DivingForPictures/Obstacles/FloatingObstacle.cs index 03b8ffb7..f23a825b 100644 --- a/Assets/Scripts/Minigames/DivingForPictures/Obstacles/FloatingObstacle.cs +++ b/Assets/Scripts/Minigames/DivingForPictures/Obstacles/FloatingObstacle.cs @@ -2,6 +2,7 @@ using System.Collections; using AppleHills.Core.Settings; using Pooling; +using Utils; namespace Minigames.DivingForPictures { @@ -182,15 +183,15 @@ namespace Minigames.DivingForPictures /// private IEnumerator MovementCoroutine() { - Debug.Log($"[FloatingObstacle] Started movement coroutine with speed: {moveSpeed:F3}"); + Debug.Log($"[FloatingObstacle] Started movement coroutine with speed: {_baseMoveSpeed:F3}"); while (enabled && gameObject.activeInHierarchy) { // Use velocity factor sign to determine direction Vector3 direction = Vector3.up * Mathf.Sign(_velocityFactor); - // Apply normalized movement with deltaTime for frame rate independence - float speed = moveSpeed * Time.deltaTime; + // Apply normalized movement using the shared utility method + float speed = AppleHillsUtils.CalculateNormalizedMovementSpeed(_baseMoveSpeed); // Apply movement in correct direction transform.position += direction * speed; diff --git a/Assets/Scripts/Minigames/DivingForPictures/Tiles/TrenchTileSpawner.cs b/Assets/Scripts/Minigames/DivingForPictures/Tiles/TrenchTileSpawner.cs index 9d4ba4e0..827cd6de 100644 --- a/Assets/Scripts/Minigames/DivingForPictures/Tiles/TrenchTileSpawner.cs +++ b/Assets/Scripts/Minigames/DivingForPictures/Tiles/TrenchTileSpawner.cs @@ -5,6 +5,7 @@ using UnityEngine.Events; using UnityEngine.Serialization; using Pooling; using AppleHills.Core.Settings; +using Utils; namespace Minigames.DivingForPictures { @@ -400,7 +401,7 @@ namespace Minigames.DivingForPictures /// private IEnumerator MovementCoroutine() { - Debug.Log($"[TrenchTileSpawner] Started movement coroutine with normalized speed: {_currentVelocity:F3}"); + Debug.Log($"[TrenchTileSpawner] Started movement coroutine with normalized speed: {_baseMoveSpeed:F3}"); while (enabled && gameObject.activeInHierarchy) { @@ -414,8 +415,8 @@ namespace Minigames.DivingForPictures // Use velocity factor sign to determine direction Vector3 direction = Vector3.up * Mathf.Sign(_velocityFactor); - // Apply normalized movement with deltaTime for frame rate independence - float speed = _currentVelocity * _screenNormalizationFactor; + // Apply normalized movement using the shared utility method + float speed = AppleHillsUtils.CalculateNormalizedMovementSpeed(_baseMoveSpeed); // Move all active tiles foreach (var tile in _activeTiles) diff --git a/Assets/Scripts/Utils/AppleHillsUtils.cs b/Assets/Scripts/Utils/AppleHillsUtils.cs index 09724245..e2dd6faf 100644 --- a/Assets/Scripts/Utils/AppleHillsUtils.cs +++ b/Assets/Scripts/Utils/AppleHillsUtils.cs @@ -1,9 +1,10 @@ using UnityEngine; +using AppleHills.Core.Settings; namespace Utils { /// - /// Utility methods for working with SpriteRenderers. + /// Utility methods for working with SpriteRenderers and game mechanics. /// public static class AppleHillsUtils { @@ -28,5 +29,43 @@ namespace Utils to.enabled = true; to.transform.localScale = from.transform.localScale; } + + /// + /// Calculates a normalized movement speed value that's consistent across different screen sizes + /// and applies the current time delta + /// + /// The base normalized speed value + /// The actual movement amount to apply per frame + public static float CalculateNormalizedMovementSpeed(float normalizedSpeed) + { + // Get settings for reference height + var settings = GameManager.GetSettingsObject(); + if (settings == null) + { + Debug.LogWarning("[AppleHillsUtils] Could not get settings, using default reference height"); + return CalculateNormalizedMovementSpeed(normalizedSpeed, 1080f); + } + + return CalculateNormalizedMovementSpeed(normalizedSpeed, settings.ReferenceScreenHeight); + } + + /// + /// Calculates a normalized movement speed value that's consistent across different screen sizes + /// and applies the current time delta + /// + /// The base normalized speed value + /// Reference screen height for normalization (typically 1080) + /// The actual movement amount to apply per frame + public static float CalculateNormalizedMovementSpeed(float normalizedSpeed, float referenceScreenHeight) + { + // Calculate the screen normalization factor + float screenNormalizationFactor = Screen.height / referenceScreenHeight; + + // Apply time delta for frame rate independence + float frameAdjustedSpeed = normalizedSpeed * Time.deltaTime; + + // Apply screen normalization + return frameAdjustedSpeed * screenNormalizationFactor; + } } } diff --git a/Assets/Settings/DivingMinigameSettings.asset b/Assets/Settings/DivingMinigameSettings.asset index a484cd4b..7caa0f87 100644 --- a/Assets/Settings/DivingMinigameSettings.asset +++ b/Assets/Settings/DivingMinigameSettings.asset @@ -32,10 +32,10 @@ MonoBehaviour: referenceScreenHeight: 1920 initialTileCount: 3 tileSpawnBuffer: 1 - normalizedTileMoveSpeed: 0.5 + normalizedTileMoveSpeed: 2 speedUpFactor: 0 speedUpInterval: 10 - maxNormalizedTileMoveSpeed: 0.5 + maxNormalizedTileMoveSpeed: 2 moveSpeed: 1 maxMoveSpeed: 12 velocityCalculationInterval: 0.5 @@ -44,7 +44,7 @@ MonoBehaviour: obstacleMaxSpawnAttempts: 10 obstacleSpawnCollisionRadius: 1 normalizedObstacleMinMoveSpeed: 1 - normalizedObstacleMaxMoveSpeed: 2 + normalizedObstacleMaxMoveSpeed: 3 damageImmunityDuration: 1 bumpForce: 5 smoothMoveSpeed: 8