43 lines
1.7 KiB
C#
43 lines
1.7 KiB
C#
using UnityEngine;
|
|
|
|
public class VRCameraIdleMotion : MonoBehaviour
|
|
{
|
|
[Header("Position Settings")]
|
|
public float positionAmplitude = 0.01f; // How far it moves (in meters)
|
|
public float positionFrequency = 1.5f; // How fast it moves
|
|
|
|
[Header("Rotation Settings")]
|
|
public float rotationAmplitude = 1.0f; // Max degrees for tilt
|
|
public float rotationFrequency = 1.2f; // How fast it rotates
|
|
|
|
private Vector3 initialPosition;
|
|
private Quaternion initialRotation;
|
|
private float timeOffset;
|
|
|
|
void Start()
|
|
{
|
|
initialPosition = transform.localPosition;
|
|
initialRotation = transform.localRotation;
|
|
timeOffset = Random.Range(0f, 100f); // Each camera can feel slightly different
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
float time = Time.time + timeOffset;
|
|
|
|
// Subtle position drift (sinusoidal)
|
|
float posOffsetY = Mathf.Sin(time * positionFrequency) * positionAmplitude;
|
|
float posOffsetX = Mathf.Cos(time * positionFrequency * 0.7f) * positionAmplitude * 0.5f;
|
|
float posOffsetZ = Mathf.Sin(time * positionFrequency * 0.5f) * positionAmplitude * 0.3f;
|
|
|
|
transform.localPosition = initialPosition + new Vector3(posOffsetX, posOffsetY, posOffsetZ);
|
|
|
|
// Subtle rotation drift (pitch & yaw mainly)
|
|
float rotOffsetX = Mathf.Sin(time * rotationFrequency) * rotationAmplitude; // pitch
|
|
float rotOffsetY = Mathf.Cos(time * rotationFrequency * 1.2f) * rotationAmplitude; // yaw
|
|
float rotOffsetZ = Mathf.Sin(time * rotationFrequency * 0.8f) * rotationAmplitude * 0.5f; // roll
|
|
|
|
transform.localRotation = initialRotation * Quaternion.Euler(rotOffsetX, rotOffsetY, rotOffsetZ);
|
|
}
|
|
}
|