Welcome to the Oculus Developer Forums!

Your participation on the forum is subject to the Oculus Code of Conduct.

In general, please be respectful and kind. If you violate the Oculus Code of Conduct, your access to the developer forums may be revoked at the discretion of Oculus staff.

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

Posts: 13
Brain Burst
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?
Tagged:

• Posts: 1,596 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.
• Posts: 13
Brain Burst
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?
• Posts: 1,596 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.
• Posts: 13
Brain Burst
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.

• Posts: 1,596 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?
• Posts: 13
Brain Burst
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));
• Posts: 1,596 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.
• Posts: 13
Brain Burst
Ok great, thanks for your time
• Posts: 23 Oculus Start Member
Hi... I think there is a workaround for that problem near the end of the following video tutorial:

• Posts: 13
Brain Burst
digibix said:
Hi... I think there is a workaround for that problem near the end of the following video tutorial:

Thanks for the video, I can confirm this seems to work for me too!
• Posts: 106 Oculus Start Member
@vrdaveb  Has the 2*Pi clamping issue been fixed as of yet out of curiosity?  If not, is this still on the roadmap to be fixed?

• Posts: 106 Oculus Start Member
No worries, the game I am working on for Touch is a bit far off, so as long as it is still on the road map I am okay to wait for a fix in the SDK rather than a temporary solution.   I'll keep an eye out for the feature in the future.
• Posts: 54
Hiro Protagonist
edited March 2018
Are there any official grabber and grabbable scripts that function properly on Gear VR controller yet or is the company still treating Gear VR like it doesn't care about it?

I wrote a grab/carry/drop script, yet now working on the throw...and already WAAAAAAAAAY over spending days on something that SHOULD be included in the Gear VR sdk for Unity...
• Posts: 106 Oculus Start Member
I ended up writing a few tutorials on how we ended up handling grabbing with Oculus Touch on my LLC's blog. The tutorials could pretty easily be ported over to the GearVR, though from my experience GearVR doesn't operate well with those motions (generally you want 2 joints to simulate moving an arm for things like grabbing, whereas GearVR can really only simulate 1). The full code for our implementation is available on our Github page if you want to check it out.
• Posts: 4,993 Valuable Player
To throw an object with a Touch controller i know i need velocity on the rigidbody to = OVRInput - must i use a script for this?

I've just picked Unity up again after a long time off and noticed a lot of things i used to have to use scripts for are built-in.  I'm just seeing how far i can go without scripts.  Thanks.