Touch up touch input
This commit is contained in:
@@ -569,13 +569,11 @@ MonoBehaviour:
|
|||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
obstaclePrefabs:
|
obstaclePrefabs:
|
||||||
- {fileID: 4743746373562280435, guid: 315a624eb99600444a51bb1d37c51742, type: 3}
|
- {fileID: 4743746373562280435, guid: 315a624eb99600444a51bb1d37c51742, type: 3}
|
||||||
spawnInterval: 2
|
spawnInterval: 3
|
||||||
spawnIntervalVariation: 1
|
spawnIntervalVariation: 1
|
||||||
maxSpawnAttempts: 10
|
maxSpawnAttempts: 10
|
||||||
spawnCollisionRadius: 1
|
spawnCollisionRadius: 1
|
||||||
spawnDistanceBelowScreen: 2
|
minMoveSpeed: 2
|
||||||
spawnRangeX: 8
|
|
||||||
minMoveSpeed: 1
|
|
||||||
maxMoveSpeed: 4
|
maxMoveSpeed: 4
|
||||||
useObjectPooling: 1
|
useObjectPooling: 1
|
||||||
maxPerPrefabPoolSize: 15
|
maxPerPrefabPoolSize: 15
|
||||||
@@ -918,6 +916,8 @@ MonoBehaviour:
|
|||||||
m_Script: {fileID: 11500000, guid: d39dbaae819c4a128a11ca60fbbc98c9, type: 3}
|
m_Script: {fileID: 11500000, guid: d39dbaae819c4a128a11ca60fbbc98c9, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
|
tapMaxDistance: 0.05
|
||||||
|
tapDecelerationRate: 5
|
||||||
--- !u!114 &747976399
|
--- !u!114 &747976399
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@@ -2075,7 +2075,7 @@ MonoBehaviour:
|
|||||||
- {fileID: 2956826569642009690, guid: 7f7f10ca24a5afe46be797daea64111a, type: 3}
|
- {fileID: 2956826569642009690, guid: 7f7f10ca24a5afe46be797daea64111a, type: 3}
|
||||||
initialTileCount: 3
|
initialTileCount: 3
|
||||||
tileSpawnBuffer: 1
|
tileSpawnBuffer: 1
|
||||||
moveSpeed: 0.7
|
moveSpeed: 1
|
||||||
speedUpFactor: 0
|
speedUpFactor: 0
|
||||||
speedUpInterval: 0
|
speedUpInterval: 0
|
||||||
maxMoveSpeed: 12
|
maxMoveSpeed: 12
|
||||||
|
|||||||
@@ -8,9 +8,19 @@ namespace Minigames.DivingForPictures
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class PlayerController : MonoBehaviour, ITouchInputConsumer
|
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 float _targetFingerX;
|
||||||
private bool _isTouchActive;
|
private bool _isTouchActive;
|
||||||
private float _originY;
|
private float _originY;
|
||||||
|
|
||||||
|
// Tap impulse system variables
|
||||||
|
private float _tapImpulseStrength = 0f;
|
||||||
|
private float _tapDirection = 0f;
|
||||||
|
|
||||||
void Awake()
|
void Awake()
|
||||||
{
|
{
|
||||||
@@ -27,13 +37,24 @@ namespace Minigames.DivingForPictures
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Handles tap input. Moves to the tapped X position.
|
/// Handles tap input. Applies an impulse in the tapped direction.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void OnTap(Vector2 worldPosition)
|
public void OnTap(Vector2 worldPosition)
|
||||||
{
|
{
|
||||||
// Debug.Log($"[EndlessDescenderController] OnTap at {worldPosition}");
|
// Debug.Log($"[EndlessDescenderController] OnTap at {worldPosition}");
|
||||||
_targetFingerX = Mathf.Clamp(worldPosition.x, GameManager.Instance.EndlessDescenderClampXMin, GameManager.Instance.EndlessDescenderClampXMax);
|
float targetX = Mathf.Clamp(worldPosition.x, GameManager.Instance.EndlessDescenderClampXMin, GameManager.Instance.EndlessDescenderClampXMax);
|
||||||
_isTouchActive = true;
|
|
||||||
|
// 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>
|
/// <summary>
|
||||||
@@ -66,21 +87,59 @@ namespace Minigames.DivingForPictures
|
|||||||
|
|
||||||
void Update()
|
void Update()
|
||||||
{
|
{
|
||||||
if (!_isTouchActive) return;
|
// Handle hold movement
|
||||||
float currentX = transform.position.x;
|
if (_isTouchActive)
|
||||||
float lerpSpeed = GameManager.Instance.EndlessDescenderLerpSpeed;
|
{
|
||||||
float maxOffset = GameManager.Instance.EndlessDescenderMaxOffset;
|
float currentX = transform.position.x;
|
||||||
float exponent = GameManager.Instance.EndlessDescenderSpeedExponent;
|
float lerpSpeed = GameManager.Instance.EndlessDescenderLerpSpeed;
|
||||||
float targetX = _targetFingerX;
|
float maxOffset = GameManager.Instance.EndlessDescenderMaxOffset;
|
||||||
float offset = targetX - currentX;
|
float exponent = GameManager.Instance.EndlessDescenderSpeedExponent;
|
||||||
offset = Mathf.Clamp(offset, -maxOffset, maxOffset);
|
float targetX = _targetFingerX;
|
||||||
float absOffset = Mathf.Abs(offset);
|
float offset = targetX - currentX;
|
||||||
float t = Mathf.Pow(absOffset / maxOffset, exponent); // Non-linear drop-off
|
offset = Mathf.Clamp(offset, -maxOffset, maxOffset);
|
||||||
float moveStep = Mathf.Sign(offset) * maxOffset * t * Time.deltaTime * lerpSpeed;
|
float absOffset = Mathf.Abs(offset);
|
||||||
// Prevent overshooting
|
float t = Mathf.Pow(absOffset / maxOffset, exponent); // Non-linear drop-off
|
||||||
moveStep = Mathf.Clamp(moveStep, -absOffset, absOffset);
|
float moveStep = Mathf.Sign(offset) * maxOffset * t * Time.deltaTime * lerpSpeed;
|
||||||
float newX = currentX + moveStep;
|
// Prevent overshooting
|
||||||
newX = Mathf.Clamp(newX, GameManager.Instance.EndlessDescenderClampXMin, GameManager.Instance.EndlessDescenderClampXMax);
|
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;
|
float newY = _originY;
|
||||||
// Add vertical offset from WobbleBehavior if present
|
// Add vertical offset from WobbleBehavior if present
|
||||||
WobbleBehavior wobble = GetComponent<WobbleBehavior>();
|
WobbleBehavior wobble = GetComponent<WobbleBehavior>();
|
||||||
|
|||||||
Reference in New Issue
Block a user