Working surfacing speedup
This commit is contained in:
@@ -61,10 +61,15 @@ namespace Minigames.DivingForPictures
|
||||
|
||||
// Direction state
|
||||
private bool _isSurfacing = false;
|
||||
|
||||
// Velocity management
|
||||
private float _baseMoveSpeed;
|
||||
private float _velocityFactor = 1.0f;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_mainCamera = Camera.main;
|
||||
_baseMoveSpeed = moveSpeed; // Store the original base speed
|
||||
|
||||
// Calculate tile heights for each prefab
|
||||
CalculateTileHeights();
|
||||
@@ -273,6 +278,23 @@ namespace Minigames.DivingForPictures
|
||||
_screenTop = top.y;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when the velocity factor changes from the DivingGameManager
|
||||
/// </summary>
|
||||
public void OnVelocityFactorChanged(float velocityFactor)
|
||||
{
|
||||
_velocityFactor = velocityFactor;
|
||||
|
||||
// Update the actual move speed based on the velocity factor
|
||||
// This keeps the original move speed intact for game logic
|
||||
moveSpeed = _baseMoveSpeed * Mathf.Abs(_velocityFactor);
|
||||
|
||||
// Recalculate velocity immediately
|
||||
CalculateVelocity();
|
||||
|
||||
Debug.Log($"[TrenchTileSpawner] Velocity factor updated to {_velocityFactor:F2}, moveSpeed: {moveSpeed:F2}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reverses direction to start surfacing
|
||||
/// </summary>
|
||||
@@ -280,17 +302,13 @@ namespace Minigames.DivingForPictures
|
||||
{
|
||||
if (_isSurfacing) return; // Already surfacing
|
||||
|
||||
// Reverse the movement direction
|
||||
moveSpeed *= -1;
|
||||
|
||||
// Update velocity immediately
|
||||
CalculateVelocity();
|
||||
// Set surfacing flag for spawn/despawn logic
|
||||
_isSurfacing = true;
|
||||
|
||||
// Reverse the active tiles array to maintain consistent indexing logic
|
||||
_activeTiles.Reverse();
|
||||
|
||||
// Set surfacing flag
|
||||
_isSurfacing = true;
|
||||
Debug.Log("[TrenchTileSpawner] Started surfacing - reversed array order");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -302,8 +320,12 @@ namespace Minigames.DivingForPictures
|
||||
{
|
||||
if (tile != null)
|
||||
{
|
||||
// Movement will automatically adapt to negative velocity when surfacing
|
||||
tile.transform.position += Vector3.up * _currentVelocity;
|
||||
// Use velocity factor to determine direction
|
||||
Vector3 direction = Vector3.up * Mathf.Sign(_velocityFactor);
|
||||
float speed = _currentVelocity;
|
||||
|
||||
// Apply movement
|
||||
tile.transform.position += direction * speed;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user