Working surfacing speedup
This commit is contained in:
@@ -48,6 +48,8 @@ namespace Minigames.DivingForPictures
|
||||
private Coroutine _movementCoroutine;
|
||||
private Coroutine _offScreenCheckCoroutine;
|
||||
private bool _isSurfacing = false; // Flag to track surfacing state
|
||||
private float _velocityFactor = 1.0f; // Current velocity factor from game manager
|
||||
private float _baseMoveSpeed; // Original move speed before velocity factor is applied
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
@@ -64,6 +66,7 @@ namespace Minigames.DivingForPictures
|
||||
}
|
||||
|
||||
_mainCamera = Camera.main;
|
||||
_baseMoveSpeed = moveSpeed; // Store original speed
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
@@ -107,6 +110,30 @@ namespace Minigames.DivingForPictures
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when the velocity factor changes from the DivingGameManager via ObstacleSpawner
|
||||
/// </summary>
|
||||
public void OnVelocityFactorChanged(float velocityFactor)
|
||||
{
|
||||
_velocityFactor = velocityFactor;
|
||||
|
||||
// Update actual move speed based on velocity factor and base speed
|
||||
// We use Abs for magnitude and Sign for direction
|
||||
moveSpeed = _baseMoveSpeed * Mathf.Abs(_velocityFactor);
|
||||
|
||||
// Restart movement with new speed if needed
|
||||
if (enableMovement && gameObject.activeInHierarchy)
|
||||
{
|
||||
if (_movementCoroutine != null)
|
||||
{
|
||||
StopCoroutine(_movementCoroutine);
|
||||
}
|
||||
_movementCoroutine = StartCoroutine(MovementCoroutine());
|
||||
}
|
||||
|
||||
Debug.Log($"[FloatingObstacle] {gameObject.name} velocity factor updated to {_velocityFactor:F2}, speed: {moveSpeed:F2}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Coroutine that handles obstacle movement
|
||||
/// </summary>
|
||||
@@ -114,8 +141,12 @@ namespace Minigames.DivingForPictures
|
||||
{
|
||||
while (enabled && gameObject.activeInHierarchy)
|
||||
{
|
||||
// Move the obstacle upward
|
||||
transform.position += Vector3.up * (moveSpeed * Time.deltaTime);
|
||||
// Use velocity factor sign to determine direction
|
||||
Vector3 direction = Vector3.up * Mathf.Sign(_velocityFactor);
|
||||
float speed = moveSpeed * Time.deltaTime;
|
||||
|
||||
// Apply movement in correct direction
|
||||
transform.position += direction * speed;
|
||||
|
||||
// Wait for next frame
|
||||
yield return null;
|
||||
|
||||
Reference in New Issue
Block a user