Ray not finding mesh (?)

take (Vector3) points p1 and p2 and a mesh at p2

this ray is not ALWAYS finding the mesh, i.e. this PickingInfo sometimes comes with hit == false:

let dir = p2.subtract(p1)
let ray = new BABYLON.Ray(p1, dir)
let inter = ray.intersectsMesh(mesh)
// sometimes inter.hit == false :frowning:

the mesh is always a polyhedron with size >= 0.01, distance between p1 and p2 is < 2.

I am struggling with this issue today…

Hope to find out that I am doing something silly or that you
have some neat explanation.

Best,
Renato

1 Like

Hello Renato,

Hope your day got a little better. There are a few things that can be happening her to look for…

First, please consider creating a PlayGround with the problem - this helps us solve whatever may be the issue.

Included is a PG where I successfully used a couple of RAYS to make a TILT-RIG

Some of the problems you may be experiencing … may be length of the ray cast.

To dial this in it is good to use the RayHelper.

  var rayHelper2 = new BABYLON.RayHelper(ray2);
  //...
  rayHelper2.show(scene, new BABYLON.Color3(.33,.44,.55));

This will allow you to see your rays.

Here is the DOCS on RayHelper

Another problem often occurs with multi-pick arrays… where the hit you are looking for is not in [0].

But it is hard for us to tell what it could be without a PG. Please consider it.

The ray casts are dependable.

:slight_smile: