cancel
Showing results for 
Search instead for 
Did you mean: 

How can I use OVRInput.GetLocalControllerAngularVelocity to affect a rigidbody.angularVelocity?

TheStonefox
Explorer
Hi all,

I'm trying to affect a rigidbody's angular velocity (which is a Vector3) based on the current angular velocity of the touch controller.

OVRInput has a GetLocalControllerAngularVelocity method but this returns a Quaternion and not a Vector3.

If I get the Eular from the returned quaternion then it's a really high number (i'm guessing it's in degrees as well) which means the rotation is way too high when affecting the rigidbody's angular velocity.

I've also tried converting the eular to radians but that doesn't seem to work correctly either.

Does anyone know how you can get the angular velocity of the controller and apply it to a rigidbody's angular velocity?
15 REPLIES 15

vrdaveb
Oculus Staff
If I get the Eular from the returned quaternion then it's a really high number

Can you give some example numbers? There is a known issue with OVRInput.GetLocalControllerAngularVelocity(..) that results in the value being clamped to (0, 2*pi) because of the use of quaternions, but I haven't heard any cases of excessively high numbers. This should be fixed in our next (late-January) release, but you can work around it for now by finding the difference between the controller's current and previous rotation and dividing by Time.deltaTime.

TheStonefox
Explorer
Hi, sure. here is the returned Quaternion: [0.8, -0.2, 0.1, -0.5]

and when I get the eular from it (with result.eular) I get [301.0, 144.8, 221.3]

As you can see those eular angles are very high for angular velocities, which causes the objects to just spin crazily.

Are you saying then at the moment to not use GetLocalControllerAngularVelocity and to get the controller's current rotation eular, and previous rotation then getting the delta of the two (b-a) and dividing by delta time?

vrdaveb
Oculus Staff
I get [301.0, 144.8, 221.3]

As you mentioned, those numbers are in degrees, so the object is rotation less than one revolution per second around each axis and should not spin crazily.

get the controller's current rotation eular, and previous rotation then getting the delta of the two (b-a) and dividing by delta time?

It depends on your use case. The problem right now is that the angular velocity gets capped at one revolution per second about any axis. If you are making a game such as darts, the bug may not affect you. For spin-the-bottle, it may limit the bottle's rotation speed.

TheStonefox
Explorer
My use case is to be able to grab an object by putting the hand anchor object (with a collider on it) into the object and pressing a button on the touch controller. Then when i move my controller and release the grabbing button on the controller, i want to throw the object in the direction and with the rotation of the controller to simulate throwing an item. I'm doing this by attempting to get the velocity and angular velocity of the controller and applying them to the object's rigidbody on release.

I can get the velocity to work fine using `GetLocalControllerVelocity` but I just can't get the Angular Velocity.

vrdaveb
Oculus Staff
It sounds like your use case should work fine with the [0, 2*pi] limit. Can you try converting from degrees to radians?

TheStonefox
Explorer
I have tried that and whilst the rotation isn't crazy fast, it isn't accurate or correct. for instance if i throw a cube up in the air, flicking my wrist backwards as i do it, i would expect the cube to spin towards me, but it goes in the opposite direction, or if i was to flick my wrist to the side, then i would expect it to rotate (through the world y) like I'm skimming a stone, but the rotation does not reflect the behaviour i would expect.

Here is an example of how I've tried the conversion:

var velocity = (OVRInput.GetLocalControllerAngularVelocity(touchControllers[device.index]).eulerAngles * Mathf.Deg2Rad);

and also: 

var velocity = (OVRInput.GetLocalControllerAngularVelocity(touchControllers[device.index]).eulerAngles * (Mathf.pi / 180f));

vrdaveb
Oculus Staff
Thanks, we'll fix this in a future release. It sounds like the best approach for now would be to do the subtract and divide (AKA numerical differentiation) as you described.

TheStonefox
Explorer
Ok great, thanks for your time

Digibix
Protege
Hi... I think there is a workaround for that problem near the end of the following video tutorial:

https://www.youtube.com/watch?v=mFFta9OszzA