Forum Discussion
vallenkilling
1 year agoHonored Guest
How To Get Contoller Veclocity (Meta SDK All-In-One)
I'm trying to get the velocity of how to get either of the VR Controllers so that it can be applied to another object when hit. I cant figure out how to aquire the velocty with the SDK setup. Any help please?
3 Replies
Replies have been turned off for this discussion
- hvox1138Protege
Hi vallenkilling,
I don't think there's a centralized place from which that value is provided, but there are tools available that will help you calculate it. For a simple calculation, you can just monitor displacement over time directly --- for example, `(controllerPositionNow - controllerPositionATenthOfASecondAgo) / 0.1 seconds`.
If you want something more sophisticated, take a look at RANSACVelocity.cs (in the essentials package > Runtime > Scripts > Throw). This is how ISDK itself calculates velocities for throwing --- you can see this usage in Grabbable.cs --- but it should be usable for calculating good, noise-resilient velocity estimates of other things too, including controllers. I don't think there's much documentation about that file yet, but if you're interested and have questions, either I or LucaMefisto should be able to help you dig deeper.
Hope this helps, and best of luck!
- LucaMefistoMeta Employee
Hi vallenkilling,
Getting the velocity of a VR Controller can be done in different ways. You can directly query it in OVRInput using (note that it is local to the tracking space):
`OVRInput.GetLocalControllerVelocity`.
Alternatively, if you want to do it without OVR and filter out possible noisy data you can use the InteractionSDK RANSACVelocity.cs class. You will have to create a component that makes use of it and attach it to a Controller thought.
Roughly speaking:
```public class ControllerVelocity : MonoBehaviour{//create the velocity calculator with a small memory to store//the last few pose samplesRANSACVelocity _velocityCalculator = new RANSACVelocity(10, 2);private void OnEnable(){//reset the calculation everytime you enable the component_velocityCalculator.Initialize();}private void Update(){//feed a timed pose every frame.//Assuming this component was parented with the controller transform_velocityCalculator.Process(this.transform.GetPose(), Time.time, true);}public Vector3 GetVelocity(){//Call this to get the filtered velocity of the controller_velocityCalculator.GetVelocities(out Vector3 velocity, out Vector3 torque);return velocity;}}
``` - IseldieraProtegeLuca's answer has what you need, but in case you need the angular velocity here is some additional info:// Get the velocity of the left controllerVector3 leftControllerVelocity = OVRInput.GetLocalControllerVelocity(OVRInput.Controller.LTouch);// Get the velocity of the right controllerVector3 rightControllerVelocity = OVRInput.GetLocalControllerVelocity(OVRInput.Controller.RTouch);// Get the angular velocity of the left controllerVector3 leftControllerAngularVelocity = OVRInput.GetLocalControllerAngularVelocity(OVRInput.Controller.LTouch);// Get the angular velocity of the right controllerVector3 rightControllerAngularVelocity = OVRInput.GetLocalControllerAngularVelocity(OVRInput.Controller.RTouch);
Quick Links
- Horizon Developer Support
- Quest User Forums
- Troubleshooting Forum for problems with a game or app
- Quest Support for problems with your device