Forum Discussion
SiggiG
12 years agoProtege
Unity 3d SDK feedback
Decided to start a thread to post feedback on and discuss the Unity3d SDK. So far so good and it's very easy to import and use :)
I've made one small tweak to the default camera script that I found very useful so maybe it's something you'd want to include in the SDK by default? It's a simple swap between absolute headset rotation and being offset by the parent object. This way you can put the OVRCameraController into another container and still look around relative to that container, for example when inside the cockpit of a spaceship.
OVRCamera.cs
New property:
And a change inside the SetCameraOrientation method:
I've made one small tweak to the default camera script that I found very useful so maybe it's something you'd want to include in the SDK by default? It's a simple swap between absolute headset rotation and being offset by the parent object. This way you can put the OVRCameraController into another container and still look around relative to that container, for example when inside the cockpit of a spaceship.
OVRCamera.cs
New property:
// Set to true if you want the camera rotation offset by parent rotation, useful when putting the user inside a vehicle
public bool OffsetByParent = false;
And a change inside the SetCameraOrientation method:
// Update camera rotation
if (this.OffsetByParent == true)
{
gameObject.camera.transform.rotation = gameObject.transform.parent.transform.rotation * q;
}
else
{
gameObject.camera.transform.rotation = q;
}
13 Replies
Replies have been turned off for this discussion
- cyberealityGrand ChampionYeah, this is totally something we'd be interested in doing for a future release.
The SDK is still a work in progress, and this is one of the things we are hoping to update for the final release. - SiggiGProtegeYeah I totally understand, and in fact I was surprised by how nice things are already.
Another idea would be do draw a Gizmo in the Unity editor to show where the actual cameras end up, this makes positioning much easier.
Btw. my code above doesn't adjust the neck model, so things shift when doing a 180° ;) - SiggiGProtegeAnother wishlist item: A simple static method to check if an Oculus Rift device is connected or not.
The current Unity integration relies on the OVRRift.cs script being in the scene so its Awake() method is called, but we want to spawn different camera prefabs based on the Oculus being connected or not.
Edit: Would it be possible to separate the plugin wrapper into it's own class that is used by the mono behavior? - cyberealityGrand ChampionCurrently the OVRPlayerController prefab takes care of initializing the Rift. It has the script OVRRift.cs attached to it.
If a Rift is not available, the static function bool OVRRift.Inited() will return false. This can be checked in a separate initialization script (make sure to check within Start, since initialization is done in Awake).
If OVRRift.Inited() returns false, then you might want to either turn off the instanced OVRPlayerController or modify it by adding another non-stereoscopic camera to it.
We may be able to refactor this a bit, so the camera is not tied to the player controller, but that's how to works now.
Hope that helps. - SiggiGProtegeThanks for the reply :)
I had cases where the Inited() method was returning true even though the HMD was disconnected. Maybe the editor was keeping the static members alive or something, but I'll do more testing to figure it out. If that is the case then it's fine, people having a Rift and disconnecting it during game development or execution is an edge case after all.
The idea you bring up is a nice compromise and I prefer that to the refactoring I've already started. I don't want to deviate too much from the standard SDK assets :) - SiggiGProtegeHey Andres,
I've done multiple tests now and with the Rift disconnected both from power and USB and the OVRRift.Inited() method always returns true. I have shut down Unity after disconnecting to be sure.
Is this a defect or something I might be missing?
Edit: Shortly after posting this it started reporting false and continues to do so even after the Rift has been connected. Is this value cached somewhere? - cyberealityGrand ChampionThanks for pointing this out. It seems that the "OVRRift.Inited()" function is not working as expected. We will get someone on this and try to fix it for an upcoming release.
What we are probably going to do is create another static function, like "OVRRift.Exists()" that will return whether the Rift is detected or not so you can branch to different paths in your application.
- Andres - SiggiGProtegeThanks Andres, that would be great :)
- SiggiGProtegeUsing SDK 0.1.4. Method OVRDevice.IsHMDPresent() still returns true with Rift disconnected.
Here's the hacky way I've been using:/// <summary>
/// Returns true if a Rift device is connected
/// </summary>
public static bool Exists()
{
float w = 0, x = 0, y = 0, z = 0;
Quaternion q = Quaternion.identity;
OVRSensorsGetOrientation(0, ref w, ref x, ref y, ref z);
q.w = w;
q.x = -x;
q.y = -y;
q.z = z;
return q.Equals(new Quaternion(0,0,0,0)) == false;
} - SiggiGProtegeI've tried multiple ways to use the OVRDevice.IsHMDPresent() method, but it's always returning true even when the Rift is not connected. I've messed with the order when I trigger the call and even when doing it on a keystroke it still returns true.
Since it's very hard to get the sensor into a state where it's returning 0 or 1, I'm using this method to detect if the Rift is there or not. The plugin returns orientation 0,0,0,1 if the Rift is disconnected./// <summary>
/// Returns true if a Rift device is connected
/// </summary>
public static bool Exists()
{
Quaternion q = Quaternion.identity;
if (OVRDevice.GetOrientation(ref q) == true)
{
return q.Equals(new Quaternion(0,0,0,1)) == false;
}
else
{
return false;
}
}
Quick Links
- Horizon Developer Support
- Quest User Forums
- Troubleshooting Forum for problems with a game or app
- Quest Support for problems with your device
Other Meta Support
Related Content
- 1 year ago