S.F. Bay Studios
S.F. Bay Studios

Reputation: 1

Modifying Rotation w/ GamePad

I'd like to modify the rotation of the camera object via a gamepad. I have code that works in the editor, but doesn't work on iOS. (However, it looks like it's working but being pushed back on the 2nd frame by the VROne code).

I was able to get this working w/ the Rift, but haven't been able to figure it out with VROne yet. For the Rift I added an "offset" to the rotation that was changed by the GamePad joystick. The offset was calculated into the final rotation that also includes the players look direction.

Any idea what part of the code I'd modify to get this properly working with the VROne sdk?

Upvotes: 0

Views: 352

Answers (3)

Alon S
Alon S

Reputation: 195

Just in case this would help someone, I was able to solve it in a much simpler way.

The VrOneSDK object is a child of the object that I am rotating with my gamepad. and then in 'vrHeadTracking.cs' I simply changed

transform.rotation = Quaternion.Inverse(initialRotation) * rot;

to

transform.localRotation = Quaternion.Inverse(initialRotation) * rot;

that way the head tracking is relative to my parent object's rotation.

Upvotes: 0

S.F. Bay Studios
S.F. Bay Studios

Reputation: 1

EDIT: Nevermind, the below code works in the editor, but on the iOS device the camera is still forced ahead. I'll try the other answer.

Cool -- that may work, the above answer. It sounds like what I was looking for.

However, per a suggestion on the Unity forum, I implemented this solution: First I made the VROne Object a child of another empty game object, with the localPosition 0,0,0.

On rotation, I rotate the parent, but first make sure the parent is the same position of the child and then the child localPosition is 0,0,0 - -right now the child is doing the physical movement, and the parent does the rotation. I'm not sure if moving the character controller to the parent would work or make something else funky in the SDK, but this seems to work for now.

if (RightStickX.Value != 0)
{
    transform.position                      = childObject.transform.position;
    childObject.transform.localPosition     = Vector3(0,0,0);
    transform.eulerAngles.y += RightStickX.Value * rotationSpeed * Time.deltaTime;
}

Upvotes: 0

Cutetare
Cutetare

Reputation: 909

If you want to use your own GameRotation angles (from the gamepad), the values might be getting overwritten by the integrated HeadTracking. Have you tried disabling the VR Head Tracking Script, in the VROneSDKHead object?

The HeadTracking angles are dealt with in the HeadTrackingIOS class, which calls the native static library. You can try adding your gamepad offset to the Quaternion returned on line 43.

Hope this helps, let us know if it worked!

Upvotes: 0

Related Questions