Move around scripts to cleanup the Minigame structure
This commit is contained in:
@@ -1,46 +0,0 @@
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Makes this object follow a target (bottleTransform) horizontally, optionally using a wobble offset for vertical movement.
|
||||
/// </summary>
|
||||
public class RockFollower : MonoBehaviour
|
||||
{
|
||||
[Header("References")]
|
||||
public Transform bottleTransform;
|
||||
public WobbleBehavior bottleWobble;
|
||||
|
||||
[Header("Movement Settings")]
|
||||
public float followStiffness = 4f;
|
||||
/// <summary>
|
||||
/// Whether to use the wobble offset for vertical movement.
|
||||
/// </summary>
|
||||
public bool useWobbleOffset = true;
|
||||
/// <summary>
|
||||
/// The base Y position for the rock.
|
||||
/// </summary>
|
||||
public float baseY = -6f;
|
||||
|
||||
private float velocityX; // For SmoothDamp
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (bottleTransform == null) return;
|
||||
|
||||
// Target horizontal position is bottle's X
|
||||
float targetX = bottleTransform.position.x;
|
||||
float currentX = transform.position.x;
|
||||
|
||||
// Smoothly follow bottle's X with stiffer motion
|
||||
float newX = Mathf.SmoothDamp(currentX, targetX, ref velocityX, 1f / followStiffness);
|
||||
|
||||
// Calculate Y position
|
||||
float newY = baseY;
|
||||
if (useWobbleOffset && bottleWobble != null)
|
||||
{
|
||||
newY += bottleWobble.VerticalOffset;
|
||||
}
|
||||
|
||||
// Set new position (only X and Y, keep Z)
|
||||
transform.position = new Vector3(newX, newY, transform.position.z);
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f1a7937fe5974e9486dc7545de8cee6b
|
||||
timeCreated: 1757020153
|
||||
@@ -1,92 +0,0 @@
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Adds a wobble (rocking and vertical movement) effect to the object, based on speed and time.
|
||||
/// </summary>
|
||||
public class WobbleBehavior : MonoBehaviour
|
||||
{
|
||||
[Header("Wobble Settings")]
|
||||
public float wobbleFrequency = 1.5f;
|
||||
/// <summary>
|
||||
/// Max degrees from horizontal.
|
||||
/// </summary>
|
||||
public float baseWobbleAmplitude = 8f;
|
||||
/// <summary>
|
||||
/// How much speed affects amplitude.
|
||||
/// </summary>
|
||||
public float speedToAmplitude = 2f;
|
||||
/// <summary>
|
||||
/// Maximum allowed rotation in degrees.
|
||||
/// </summary>
|
||||
public float maxRotationLimit = 45f;
|
||||
|
||||
[Header("Vertical Movement Settings")]
|
||||
public float verticalFrequency = 0.5f;
|
||||
/// <summary>
|
||||
/// How far the object moves up/down.
|
||||
/// </summary>
|
||||
public float verticalAmplitude = 0.5f;
|
||||
|
||||
[Header("Smoothing Settings")]
|
||||
public float velocitySmoothing = 10f;
|
||||
/// <summary>
|
||||
/// How quickly rotation is smoothed.
|
||||
/// </summary>
|
||||
public float rotationSmoothing = 10f;
|
||||
|
||||
private Vector3 lastPosition;
|
||||
private float wobbleTime;
|
||||
private float velocity;
|
||||
private Vector3 basePosition;
|
||||
private float verticalOffset;
|
||||
private float smoothedVelocity;
|
||||
private float smoothedAngle;
|
||||
|
||||
/// <summary>
|
||||
/// The current velocity of the object (horizontal only).
|
||||
/// </summary>
|
||||
public float Velocity => velocity;
|
||||
/// <summary>
|
||||
/// The current vertical offset due to wobble.
|
||||
/// </summary>
|
||||
public float VerticalOffset => verticalOffset;
|
||||
|
||||
void Start()
|
||||
{
|
||||
lastPosition = transform.position;
|
||||
smoothedVelocity = 0f;
|
||||
smoothedAngle = 0f;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
// Calculate movement speed (exclude vertical wobble from velocity calculation)
|
||||
Vector3 horizontalPosition = transform.position;
|
||||
horizontalPosition.y = 0f; // Ignore Y for velocity if only horizontal movement matters
|
||||
Vector3 horizontalLastPosition = lastPosition;
|
||||
horizontalLastPosition.y = 0f;
|
||||
velocity = (horizontalPosition - horizontalLastPosition).magnitude / Time.deltaTime;
|
||||
lastPosition = transform.position;
|
||||
|
||||
// Smooth velocity to prevent jitter
|
||||
smoothedVelocity = Mathf.Lerp(smoothedVelocity, velocity, velocitySmoothing * Time.deltaTime);
|
||||
|
||||
// Wobble amplitude scales with smoothed speed, but always has a base value
|
||||
float amplitude = baseWobbleAmplitude + smoothedVelocity * speedToAmplitude;
|
||||
amplitude = Mathf.Min(amplitude, maxRotationLimit); // Prevent amplitude from exceeding limit
|
||||
|
||||
// Oscillate around horizontal (0 degrees)
|
||||
wobbleTime += Time.deltaTime * wobbleFrequency;
|
||||
float targetAngle = Mathf.Sin(wobbleTime) * amplitude;
|
||||
targetAngle = Mathf.Clamp(targetAngle, -maxRotationLimit, maxRotationLimit);
|
||||
|
||||
// Smooth the rotation angle
|
||||
smoothedAngle = Mathf.Lerp(smoothedAngle, targetAngle, rotationSmoothing * Time.deltaTime);
|
||||
|
||||
// Apply rotation (Z axis for 2D)
|
||||
transform.localRotation = Quaternion.Euler(0f, 0f, smoothedAngle);
|
||||
|
||||
// Calculate vertical up/down movement (wave riding) only once
|
||||
verticalOffset = Mathf.Sin(wobbleTime * verticalFrequency) * verticalAmplitude;
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9072050a53fc4b539f4f4716bab53c07
|
||||
timeCreated: 1757017852
|
||||
Reference in New Issue
Block a user