Touch up touch input

This commit is contained in:
2025-09-22 15:01:53 +02:00
parent da07f778c3
commit 1a9c82f5d7
2 changed files with 82 additions and 23 deletions

View File

@@ -569,13 +569,11 @@ MonoBehaviour:
m_EditorClassIdentifier:
obstaclePrefabs:
- {fileID: 4743746373562280435, guid: 315a624eb99600444a51bb1d37c51742, type: 3}
spawnInterval: 2
spawnInterval: 3
spawnIntervalVariation: 1
maxSpawnAttempts: 10
spawnCollisionRadius: 1
spawnDistanceBelowScreen: 2
spawnRangeX: 8
minMoveSpeed: 1
minMoveSpeed: 2
maxMoveSpeed: 4
useObjectPooling: 1
maxPerPrefabPoolSize: 15
@@ -918,6 +916,8 @@ 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
@@ -2075,7 +2075,7 @@ MonoBehaviour:
- {fileID: 2956826569642009690, guid: 7f7f10ca24a5afe46be797daea64111a, type: 3}
initialTileCount: 3
tileSpawnBuffer: 1
moveSpeed: 0.7
moveSpeed: 1
speedUpFactor: 0
speedUpInterval: 0
maxMoveSpeed: 12

View File

@@ -8,10 +8,20 @@ namespace Minigames.DivingForPictures
/// </summary>
public class PlayerController : MonoBehaviour, ITouchInputConsumer
{
[Header("Tap Movement")]
[Tooltip("Maximum distance the player can move from a single tap")]
[SerializeField] private float tapMaxDistance = 0.5f;
[Tooltip("How quickly the tap impulse fades (higher = faster stop)")]
[SerializeField] private float tapDecelerationRate = 5.0f;
private float _targetFingerX;
private bool _isTouchActive;
private float _originY;
// Tap impulse system variables
private float _tapImpulseStrength = 0f;
private float _tapDirection = 0f;
void Awake()
{
_originY = transform.position.y;
@@ -27,13 +37,24 @@ namespace Minigames.DivingForPictures
}
/// <summary>
/// Handles tap input. Moves to the tapped X position.
/// Handles tap input. Applies an impulse in the tapped direction.
/// </summary>
public void OnTap(Vector2 worldPosition)
{
// Debug.Log($"[EndlessDescenderController] OnTap at {worldPosition}");
_targetFingerX = Mathf.Clamp(worldPosition.x, GameManager.Instance.EndlessDescenderClampXMin, GameManager.Instance.EndlessDescenderClampXMax);
_isTouchActive = true;
float targetX = Mathf.Clamp(worldPosition.x, GameManager.Instance.EndlessDescenderClampXMin, GameManager.Instance.EndlessDescenderClampXMax);
// Calculate tap direction (+1 for right, -1 for left)
_tapDirection = Mathf.Sign(targetX - transform.position.x);
// Set impulse strength to full
_tapImpulseStrength = 1.0f;
// Store target X for animation purposes
_targetFingerX = targetX;
// Do not set _isTouchActive for taps anymore
// _isTouchActive = true; - Removed to prevent continuous movement
}
/// <summary>
@@ -66,21 +87,59 @@ namespace Minigames.DivingForPictures
void Update()
{
if (!_isTouchActive) return;
float currentX = transform.position.x;
float lerpSpeed = GameManager.Instance.EndlessDescenderLerpSpeed;
float maxOffset = GameManager.Instance.EndlessDescenderMaxOffset;
float exponent = GameManager.Instance.EndlessDescenderSpeedExponent;
float targetX = _targetFingerX;
float offset = targetX - currentX;
offset = Mathf.Clamp(offset, -maxOffset, maxOffset);
float absOffset = Mathf.Abs(offset);
float t = Mathf.Pow(absOffset / maxOffset, exponent); // Non-linear drop-off
float moveStep = Mathf.Sign(offset) * maxOffset * t * Time.deltaTime * lerpSpeed;
// Prevent overshooting
moveStep = Mathf.Clamp(moveStep, -absOffset, absOffset);
float newX = currentX + moveStep;
newX = Mathf.Clamp(newX, GameManager.Instance.EndlessDescenderClampXMin, GameManager.Instance.EndlessDescenderClampXMax);
// Handle hold movement
if (_isTouchActive)
{
float currentX = transform.position.x;
float lerpSpeed = GameManager.Instance.EndlessDescenderLerpSpeed;
float maxOffset = GameManager.Instance.EndlessDescenderMaxOffset;
float exponent = GameManager.Instance.EndlessDescenderSpeedExponent;
float targetX = _targetFingerX;
float offset = targetX - currentX;
offset = Mathf.Clamp(offset, -maxOffset, maxOffset);
float absOffset = Mathf.Abs(offset);
float t = Mathf.Pow(absOffset / maxOffset, exponent); // Non-linear drop-off
float moveStep = Mathf.Sign(offset) * maxOffset * t * Time.deltaTime * lerpSpeed;
// Prevent overshooting
moveStep = Mathf.Clamp(moveStep, -absOffset, absOffset);
float newX = currentX + moveStep;
newX = Mathf.Clamp(newX, GameManager.Instance.EndlessDescenderClampXMin, GameManager.Instance.EndlessDescenderClampXMax);
UpdatePosition(newX);
}
// Handle tap impulse movement
else if (_tapImpulseStrength > 0)
{
float currentX = transform.position.x;
float maxOffset = GameManager.Instance.EndlessDescenderMaxOffset;
float lerpSpeed = GameManager.Instance.EndlessDescenderLerpSpeed;
// Calculate move distance based on impulse strength
float moveDistance = maxOffset * _tapImpulseStrength * Time.deltaTime * lerpSpeed;
// Limit total movement from single tap
moveDistance = Mathf.Min(moveDistance, tapMaxDistance * _tapImpulseStrength);
// Apply movement in tap direction
float newX = currentX + (moveDistance * _tapDirection);
newX = Mathf.Clamp(newX, GameManager.Instance.EndlessDescenderClampXMin, GameManager.Instance.EndlessDescenderClampXMax);
// Reduce impulse strength over time
_tapImpulseStrength -= Time.deltaTime * tapDecelerationRate;
if (_tapImpulseStrength < 0.01f)
{
_tapImpulseStrength = 0f;
}
UpdatePosition(newX);
}
}
/// <summary>
/// Updates the player's position with the given X coordinate
/// </summary>
private void UpdatePosition(float newX)
{
float newY = _originY;
// Add vertical offset from WobbleBehavior if present
WobbleBehavior wobble = GetComponent<WobbleBehavior>();