Raycasting is not working in immersive mode as expected

We are using pc.app.systems.rigidbody.raycastFirst() to retrieve the entity details for which collision component is added. It is working fine in web mode but in immersive mode , it is not detecting the collision entities always returing null. We have used the below code to get the raycast result

this.collisionEntity = pc.app.systems.rigidbody.raycastFirst(this.inputSource.getOrigin(), this.inputSource.getDirection());

So please guide us , how to get the ray cast result in immersive mode.
Thanks in advance.

It’s possibly related to this issue:

and so the ray is perhaps incorrect.

1 Like

Is this AR or VR?

It is in VR

Raycasting in physics should work.

However, raycastFirst takes a start point and an end point, not a start point and direction which is what you are currently doing:

https://developer.playcanvas.com/en/api/pc.RigidBodyComponentSystem.html#raycastFirst

1 Like

Thanks for the reply.
Do you have any suggestions that what can we pass to raycastFirst in case VR mode. So far we are passing as like below
pc.app.systems.rigidbody.raycastFirst(this.inputSource.getOrigin(), this.inputSource.getDirection());
But as we understood we need to pass end point instead of direction , Can you suggest us what can we pass because as we checked that XRInputSource’s ray contains origin and direction , So we can’t identify what exactly we can pass in case of VR mode.

You will need to project an end point based on the origin and the direction.

ie:

// Project the end point 10 units in the direction of the inputSource
var endPoint  = this.inputSource.getDirection().clone().scale(10);
endPoint.add(this.inputSource.getOrigin());

Thanks for your guidance. It’s working fine now.