Hi everyone,
I’m taking my first steps working on a simpleVR project in Unity 2022 using a VR Google setup, and I’m trying to achieve a unique camera movement system. Here’s what I’m aiming for:
- Camera Path Progression: I want my VR camera to follow a predefined path, where moving along the path is controlled by the rotation of the player’s head. Essentially, a full 360° turn of the head should move the camera from the start to the end of the path.
- Looking at Closest Objects: As the camera progresses along the path, I’d like it to dynamically look at the nearest objects within a certain range.
I’ve considered using Cinemachine (I have it installed), but I’m not sure how to fully integrate it for smooth path-following based on head rotation. If anyone has experience with Cinemachine for VR or similar setups, I’d really appreciate any examples or tips!
I’ve tried using head rotation angles to calculate position on the path, but I’m struggling with smoothly moving the camera and detecting/looking at the closest objects. I’d appreciate any example scripts or guidance on achieving this effect!
Here’s a chatgpt mockup but as noob for programming this only brings me so far
public Transform[] pathPoints; // Array of points on the path
private float currentProgress = 0f; // Track progress along the path
public Transform cameraTransform;
void Update() {
// Get rotation and map it to 0-1 range
float rotationY = Mathf.Repeat(cameraTransform.eulerAngles.y, 360f);
float pathProgress = rotationY / 360f;
// Update camera position along path based on progress
Vector3 position = Vector3.Lerp(pathPoints[0].position, pathPoints[pathPoints.Length - 1].position, pathProgress);
cameraTransform.position = position;
// Find the closest object and look at it
Transform closestObject = FindClosestObject();
if (closestObject != null) {
cameraTransform.LookAt(closestObject);
}
}
Transform FindClosestObject() {
// Placeholder for closest object detection logic
return null;
}
Thanks so much for any help!