Big script cleanup. Remove the examples from Ropes' external package
This commit is contained in:
46
Assets/Scripts/Movement/RockFollower.cs
Normal file
46
Assets/Scripts/Movement/RockFollower.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user