Jump to content

Intersecting mesh with BABYLON.Ray from VR Controller


Recommended Posts


I am using Babylon.js with HTC Vive and WebVR and I want to pick a point on the mesh (this.wallMesh) with controller ray. I don't want to use default VRHelper interactions.

I expected that this code should work for it but it seems that there is wrong rotation because the rotation of the device behaves totally weird.

Do you have some tips on how to fix it? Thank you a lot.

const pickMesh = BABYLON.Mesh.CreateSphere(

const ray = new BABYLON.Ray(

this.scene.registerAfterRender(() => {

    ray.origin = controller.devicePosition;
    ray.direction = controller.deviceRotationQuaternion.toEulerAngles();

    const hit = this.wallMesh!
        .pickWithRay(ray, (mesh) => mesh === this.wallMesh);

    if (hit) {

        if (hit.pickedPoint) {
            pickMesh.position = hit.pickedPoint;





Link to comment
Share on other sites

Hey @PavolHejný, from a quick look
ray.direction = controller.deviceRotationQuaternion.toEulerAngles();

looks incorrect, instead to get a direction for your ray you can rotate a forward vector by your rotation quaternion.

var m = new BABYLON.Matrix();
var direction = Vector3.TransformCoordinates(BABYLON.Vector3.Forward(), m);

Let me know if that doesn't work.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...