- Home /
Recenter or Reorient scene on Unity with Cardboard SDK
With Unity, the CardboardHead script is added to the main camera and that handles everything quite nicely, but I need to be able to "recenter" the view on demand and the only option I see so far is to rorate the entire scene and it seems like this is something the would address first-hand and I can't find anything in the docs.
With Oculus Mobile SDK (GearVR), it would be OVRCamera.ResetCameraPositionOrientation(Vector3.one, Vector3.zero, Vector3.up, Vector3.zero); though they handle it nicely each time the viewer is put on so it's rarely needed there.
P.S. Can't add a "topic" because I'm new? Good way to keep new user segments from being affective (or adopting) this system. "Google Cardboard"
You should put the code having issues in your topic, we cannot imagine what you're doing. PS: it's not that you "cannot add topic", just the topics from new users go under moderation until you get some "karma points" (that you get by questions and answers you post).
I don't have any code. That's the point :) I'm looking for ideas. As I said, I could rotate the entire scene, but orienting the user is the first thing a VR app must do so it seems like something that should be handled nicely in the Cardboard SD$$anonymous$$ and I'd guess that I'm just not seeing it.
I COULD NOT create a new topic. Literally, it said that I need 50 points to create a new topic.
Answer by ksVPN · Feb 12, 2015 at 03:52 PM
I asked this question the other day without seeing your question. I did something that worked for me and maybe it'll help you and others. I'll mention it here and on my own question for future searchers.
My biggest problem was that Cardbaord.SDK.HeadRotation is read-only and it's a Quaternion that is stuck in 3D space and can't be manipulated like you want. So instead of using the Cardboard.SDK.HeadRotation to directly control your camera game object's position, I calculated the change in rotation between updates and applied that rotation to my camera game object.
I'm very new to this and I'm writing this example code off the top of my head, so there may be errors, but it's close to what I've implemented that is working.
//used to set a game-object, such as a parent, as a point reference for resetting view
public Transform target;
private Quaternion prevRotation;
void Start () {
//set your first rotation as starting head rotation
prevRotation = Cardboard.SDK.HeadRotation;
}
void Update () {
//on button push
if (Input.GetButton ("Reset")) {
//doesn't have to reset to target, can reset to anything you need
//such as Quaternion.identity
transform.rotation = target.rotation;
} else {
//here you set the the rotation to the difference between the current head
//rotation and your previous head rotation
var rot = Quaternion.Euler (Cardboard.SDK.HeadRotation.eulerAngles
- prevRotation.eulerAngles);
//add this difference to current rotation by using the Quaternion operator '*'
transform.rotation *= rot;
}
//save the current head rotation as prevRotation to be used next update
prevRotation = Cardboard.SDK.HeadRotation;
}
Please note I'm new to unity and programming in general, but this is currently working for the game I made, so I hope it helps!
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Cardboard black screen on launch 0 Answers