[Diving][Input] First doodle on first minigame with basic controller
This commit is contained in:
54
Assets/Scripts/EndlessDescenderController.cs
Normal file
54
Assets/Scripts/EndlessDescenderController.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class EndlessDescenderController : MonoBehaviour, ITouchInputConsumer
|
||||
{
|
||||
private float targetFingerX;
|
||||
private bool isTouchActive;
|
||||
|
||||
void Start()
|
||||
{
|
||||
// Register as default consumer for input
|
||||
InputManager.Instance?.SetDefaultConsumer(this);
|
||||
// Initialize target to current position
|
||||
targetFingerX = transform.position.x;
|
||||
isTouchActive = false;
|
||||
}
|
||||
|
||||
public void OnTouchPress(Vector2 worldPosition)
|
||||
{
|
||||
// Only update horizontal position
|
||||
targetFingerX = Mathf.Clamp(worldPosition.x, GameManager.Instance.EndlessDescenderClampXMin, GameManager.Instance.EndlessDescenderClampXMax);
|
||||
isTouchActive = true;
|
||||
}
|
||||
|
||||
public void OnTouchPosition(Vector2 worldPosition)
|
||||
{
|
||||
// Update target x as finger moves
|
||||
targetFingerX = Mathf.Clamp(worldPosition.x, GameManager.Instance.EndlessDescenderClampXMin, GameManager.Instance.EndlessDescenderClampXMax);
|
||||
}
|
||||
|
||||
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);
|
||||
Vector3 oldPos = transform.position;
|
||||
transform.position = new Vector3(newX, transform.position.y, transform.position.z);
|
||||
Debug.Log($"EndlessDescenderController: Moved from {oldPos} to {transform.position} (targetX={targetX}, lerpSpeed={lerpSpeed}, offset={offset}, exponent={exponent}, moveStep={moveStep})");
|
||||
}
|
||||
|
||||
// Optionally, handle touch release if needed
|
||||
// You can add a method to reset isTouchActive if desired
|
||||
}
|
||||
3
Assets/Scripts/EndlessDescenderController.cs.meta
Normal file
3
Assets/Scripts/EndlessDescenderController.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d39dbaae819c4a128a11ca60fbbc98c9
|
||||
timeCreated: 1757014906
|
||||
@@ -69,4 +69,9 @@ public class GameManager : MonoBehaviour
|
||||
return null;
|
||||
}
|
||||
// Add more accessors as needed
|
||||
public float EndlessDescenderLerpSpeed => gameSettings != null ? gameSettings.endlessDescenderLerpSpeed : 12f;
|
||||
public float EndlessDescenderMaxOffset => gameSettings != null ? gameSettings.endlessDescenderMaxOffset : 3f;
|
||||
public float EndlessDescenderClampXMin => gameSettings != null ? gameSettings.endlessDescenderClampXMin : -5f;
|
||||
public float EndlessDescenderClampXMax => gameSettings != null ? gameSettings.endlessDescenderClampXMax : 5f;
|
||||
public float EndlessDescenderSpeedExponent => gameSettings != null ? gameSettings.endlessDescenderSpeedExponent : 2.5f;
|
||||
}
|
||||
|
||||
@@ -28,6 +28,18 @@ public class GameSettings : ScriptableObject
|
||||
[Header("Default Prefabs")]
|
||||
public GameObject basePickupPrefab;
|
||||
|
||||
[Header("Endless Descender Settings")]
|
||||
[Tooltip("How quickly the character follows the finger horizontally (higher = more responsive)")]
|
||||
public float endlessDescenderLerpSpeed = 12f;
|
||||
[Tooltip("Maximum horizontal offset allowed between character and finger position")]
|
||||
public float endlessDescenderMaxOffset = 3f;
|
||||
[Tooltip("Minimum allowed X position for endless descender movement")]
|
||||
public float endlessDescenderClampXMin = -3.5f;
|
||||
[Tooltip("Maximum allowed X position for endless descender movement")]
|
||||
public float endlessDescenderClampXMax = 3.5f;
|
||||
[Tooltip("Exponent for speed drop-off curve (higher = sharper drop near target)")]
|
||||
public float endlessDescenderSpeedExponent = 2.5f;
|
||||
|
||||
[System.Serializable]
|
||||
public class CombinationRule {
|
||||
public PickupItemData itemA;
|
||||
@@ -75,4 +87,9 @@ public class GameSettings : ScriptableObject
|
||||
public static float FollowerSpeedMultiplier => Instance.followerSpeedMultiplier;
|
||||
public static float HeldIconDisplayHeight => Instance.heldIconDisplayHeight;
|
||||
public static GameObject BasePickupPrefab => Instance.basePickupPrefab;
|
||||
public static float EndlessDescenderLerpSpeed => Instance.endlessDescenderLerpSpeed;
|
||||
public static float EndlessDescenderMaxOffset => Instance.endlessDescenderMaxOffset;
|
||||
public static float EndlessDescenderClampXMin => Instance.endlessDescenderClampXMin;
|
||||
public static float EndlessDescenderClampXMax => Instance.endlessDescenderClampXMax;
|
||||
public static float EndlessDescenderSpeedExponent => Instance.endlessDescenderSpeedExponent;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user