Hello,
I am making a plane game on Vive. I would like to have multiple point of views, in order to do that i changed the position of the CameraRig (too small to go on all the positions at once).
And I would like to reset the position of the eye camera exactly on a dummy (to be sure the head is where I want). But I don’t know how to do it.
Yes can’t manage to make it work ether, I fell like I miss something, is this function suppose to place the camera at is parent position? How does he know which camera, and parent, it is ?
I spent a lot of time looking for an answer on this. Eventually wrote this script which took care of it to my liking.
This script will allow a reset of the SteamVR camera rig to align with a transform representing the desired head position in the scene. Attach to any GameObject in the scene. Useful for seated experiences like cockpits.
using UnityEngine;
public class ResetSeatedPosition : MonoBehaviour {
[Tooltip("Desired head position of player when seated")]
public Transform desiredHeadPosition;
private Transform steamCamera;
private Transform steamController;
// Update is called once per frame
void Update () {
if (Input.GetKeyDown(KeyCode.Space))
{
if (desiredHeadPosition != null)
{
ResetSeatedPos(desiredHeadPosition);
}
else
{
Debug.Log("Target Transform required. Assign in inspector.");
}
}
}
private void ResetSeatedPos(Transform desiredHeadPos){
//find VR Camera and CameraRig transforms in scene
steamCamera = FindObjectOfType<SteamVR_Camera>().gameObject.transform;
steamController = FindObjectOfType<SteamVR_ControllerManager>().transform;
if ((steamCamera != null) && (steamController != null))
{
//{first rotation}
//get current head heading in scene
//(y-only, to avoid tilting the floor)
float offsetAngle = steamCamera.rotation.eulerAngles.y;
//now rotate CameraRig in opposite direction to compensate
steamController.Rotate(0f, -offsetAngle, 0f);
//{now position}
//calculate postional offset between CameraRig and Camera
Vector3 offsetPos = steamCamera.position - steamController.position;
//reposition CameraRig to desired position minus offset
steamController.position = (desiredHeadPos.position - offsetPos);
Debug.Log("Seat recentered!");
}
else
{
Debug.Log("Error: SteamVR objects not found!");
}
}
}
Turned out to be simpler than I expected. Hope it can save someone else the time!