[Diving] Movement with a rock and 3 ropes is working

This commit is contained in:
Michal Pikulski
2025-09-04 23:13:19 +02:00
parent d34eb77e20
commit fbb658098b
110 changed files with 28707 additions and 4 deletions

View File

@@ -0,0 +1,38 @@
using UnityEngine;
public class RockFollower : MonoBehaviour
{
[Header("References")]
public Transform bottleTransform; // Assign the bottle's transform in inspector or via script
public WobbleBehavior bottleWobble; // Assign if you want to use vertical offset
[Header("Movement Settings")]
public float followStiffness = 4f; // Higher = stiffer, lower = more responsive
public bool useWobbleOffset = true; // Should the rock follow the bottle's vertical wobble?
public float baseY = -6f; // The base Y position for the rock
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);
}
}