# How to prevent ray collisions with certain meshes

Im using
ray = new Ray(B2, new Vector3(0, -1, 0), 1000);
hit = scene.pickWithRay(ray);

to look for the point of collision between the ray and a specific mesh, but I have other meshes that are interfering and receiving the hit instead, how can I hide, disable, prevent etc other meshes from appearing in the hit collisions?

thank you

found solution doing
mesh.isPickable = false;

1 Like

Other solution is to pass a predicate as the 2nd parameter of `scene.pickWithRay`.

1 Like

@Evgeni_Popov thatÂ´s very nice Evgeni, so I can tell it to only look for collisions with a specific mesh, thats also a great way yeah

@Evgeni_Popov what does it mean a â€śpredicateâ€ť ? I am trying this:
hit = scene.pickWithRay(ray, mhr[mcur]);
putting the mesh that I care about, and it gives error â€śTypeError: predicate is not a functionâ€ť,
what kind of a parameter is this predicate, any examples around? do I have to set a function that returns the mesh? or?
I tried this:

hit = scene.pickWithRay(ray, ()=>{return mhr[mcur];});

and then I donâ€™t get error, but I donâ€™t get any collisions either

by the way mhr[mcur] is the variable of the mesh I care about

The predicate in this case is simply a function that takes a mesh as a parameter and should return true or false to indicate that this mesh should be tested or not.

``````hit = scene.pickWithRay(ray, (mesh)=> { return mesh.name === "mymesh"; });
``````

You can of course put the logic you want inside the function:

``````mymesh = new BABYLON.Mesh(...);
hit = scene.pickWithRay(ray, (mesh)=> { return mesh === mymesh; });
``````
``````const meshesToTest = {};
meshesToTest[mesh1.uniqueId] = true;
meshesToTest[mesh2.uniqueId] = true;
...
hit = scene.pickWithRay(ray, (mesh)=> { return meshesToTest[mesh.uniqueId] === true; });
``````
2 Likes

very helpful thank you very much