- Home /
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
Answer by SteenPetersen · May 14, 2019 at 06:13 AM
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.
Hello!
I'm new to VR development so maybe this is a dumb question but, how do access to controller.currentVelocity? I mean, how do you obtain the "controller" object?
Thanks!
Answer by wyatts · May 11, 2019 at 12:02 AM
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; }
Hey thanks for the input, Im making my own framework so im not using S$$anonymous$$mVR or oculus or anything building everything to work native with Unity.
As it is now I am already fetching the angular velocity and velocity of the controllers from the tracked nodes (ref).
In that case you'd want to calculate the velocity manually using transform.localposition ins$$anonymous$$d of the apparent default of worldspace. $$anonymous$$aybe this is unfounded, but my only concern with that is the further away you get from raw input the more room for issues - for example different controllers might not translate the velocity calculations the same.