I need help with a hand script I made, its supposed to be mainly like "Granny" where theres a delay with rotation but not position. It only works for random models and I don't know why. It's suppost to be an empty object as the child of the camera and converts the motion to a world space position, then convert it back. Here's the script for anyone who can help:
using UnityEngine;
public class HandScript : MonoBehaviour
{
[Header("Delay Settings")]
[Tooltip("How quickly the hand catches up to the camera rotation.")]
public float rotationLagSpeed = 5f;
[Tooltip("Optional offset from the camera's rotation.")]
public Vector3 rotationOffsetEuler = Vector3.zero;
private Transform cameraRoot;
private Quaternion currentWorldRotation;
void Start()
{
cameraRoot = Camera.main.transform; // top-level camera
currentWorldRotation = transform.rotation; // store initial world rotation
}
void LateUpdate()
{
if (cameraRoot == null) return;
// Target rotation in world space: camera's world rotation + offset
Quaternion targetWorldRotation = cameraRoot.rotation * Quaternion.Euler(rotationOffsetEuler);
// Smoothly interpolate in world space
currentWorldRotation = Quaternion.Slerp(currentWorldRotation, targetWorldRotation, rotationLagSpeed * Time.deltaTime);
// Apply the lagged rotation in world space
transform.rotation = currentWorldRotation;
}
}