Can I get controller movement?

Hi. I want to know if it is possible to get the xr controller movement. As example, if it is getting closer to an object or not, or the distance between this object and controller. Any sugestions are welcome :wink:
Ping @RaananW


you could track and calculate the deltas on each frame, just like you would with any moving object. There is no magic other than that :slight_smile:

Thanks @RaananW.
I tried something
Something like this?

Sure! if it fits your usecase, why not :slight_smile:
I would personally use DistanceSquared, especially if you can calculate a squared distance from the object. It saves one Math.sqrt call each frame, which will increase performance a bit.

Great, thanks.
I’m trying to make a difference between click and drag on an object, without succes till now, but keep trying :wink:

Why don’t you use the pointer system? pointerdown + pointermove will give you drag, pointerdown + pointerup will give you a click

This is a good idea, but how I know from scene pointer which controller clicked or dragged the object? (because on drag I want to parent the draggable object to the controller.
Sorry for bothering you

You are not bothering at all! :slight_smile:

Every pointer event has a pointerId, which is a number (kind of like an index) - located at pointerInfo.event.pointerId. You can get the controller corresponding to this ID using getXRControllerByPointerId in the xr pointer feature. You can also write your own logic using this number. The number will stay the same as long as the controller is still detected, so you can use it to compare between events.

1 Like

I got it to woooork :fire:
Thank you


Makes me very happy to read :slight_smile:

1 Like