cancel
Showing results for 
Search instead for 
Did you mean: 

How To Get Contoller Veclocity (Meta SDK All-In-One)

vallenkilling
Honored Guest

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 3

hvox1138
Protege

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!

LucaMefisto
Explorer

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 samples
    RANSACVelocity _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;
    }
}
```




Iseldiera
Protege
Luca'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 controller
Vector3 leftControllerVelocity = OVRInput.GetLocalControllerVelocity(OVRInput.Controller.LTouch);
 
// Get the velocity of the right controller
Vector3 rightControllerVelocity = OVRInput.GetLocalControllerVelocity(OVRInput.Controller.RTouch);
 
// Get the angular velocity of the left controller
Vector3 leftControllerAngularVelocity = OVRInput.GetLocalControllerAngularVelocity(OVRInput.Controller.LTouch);
 
// Get the angular velocity of the right controller
Vector3 rightControllerAngularVelocity = OVRInput.GetLocalControllerAngularVelocity(OVRInput.Controller.RTouch);