AngularVelocity/Velocity relative to a CameraRig (VR) - Throwing Objects wrong direction

Hi,

im in a bit of a pickle. I am working on trying to make objects that I release from my hand in VR adopt the correct velocity and angularVelocity of the controller so they feel correct. This is a simple matter of tracking the controller angularvelocity and velocity and passing it to the opbject upon release:

rigid.velocity = controller.currentVelocity;
rigid.angularVelocity = controller.currentAngularVelocity;

However, and here comes the kicker, I also have a locomotion system that happens to rotate the CameraRig with regards to the head of the player and after doing so these values are all wrong and shifted with regards to the cameraRig as so:

cameraRig.transform.RotateAround(headsetCamera.transform.position, Vector3.up, -(headsetCamera.transform.eulerAngles.y - lastHeadRot.y));
lastHeadRot = headsetCamera.transform.eulerAngles;

That’s basically it, If I use other forms of locomotion angularVelocity gets set properly and works fine, but after shifting the world with the above code it messes up ther calculations entirely. Im wondering what I can do about this. Any suggestions?

Thank you for your attention.

@aldonaletto

It’s seemingly simple, but there are some very complex formulas that can go into realistic feeling throws. Take a look at the SteamVR throwable scripts and you’ll see what I mean.

In response to your issue you’d need to get the velocity of the tracked object in local space. Depending on how you’re doing this you might have to calculate the velocity manually. Or if using SteamVR you could reference the SteamVR_Behaviour_Pose.cs script and this method: public Vector3 GetVelocity() { return poseAction[inputSource].velocity; }

I solved this finally, so I thought I would add the solution here.

Instead of using this code to throw objects:

 _rigid.velocity = controller.currentVelocity;
 _rigid.angularVelocity = controller.currentAngularVelocity;

I used:

 _rigid.AddForce(controller.currentVelocity);
 _rigid.angularVelocity = controller.currentAngularVelocity;

this solved the issue and the objects now fly in the expected direction no matter what the roation of the parent is.