Detecting position on surface of mesh after moving a point in mesh on a certain direction by a certain amount

@JohnK so the good news is that if i do something really crazy, which is to put position of sphere and arrow way out on top of mesh before all the ray stuff, then it works, it always hits the mesh, and then I update the ball and arrow and back to start, and then it kind of works, but this is not a good solution of course :slight_smile: i need to find another way, I wonder is there a way to kind of disable meshes to make them not hittable by the rays temporarily or something

@JohnK the other thing i really need is how to stop and restart the event
derObs=scene.onAfterRenderObservable.add(() => {

if (hit.pickedMesh === mhr[mcur]){
scene.onBeforeRenderObservable.remove(derObs);

because that just doesnt work, it doesnt stop the event

@JohnK found solution John, we just gotta use
mesh.isPickable = false;
and that solves all the collision stuff

@JohnK so all that I have left now is to be able to stop this event
derObs=scene.onAfterRenderObservable.add(() => {
whenever I like, I am trying to understand why it wont stop

update: found the reason, I was mixing events, onAfterRenderObservable with beforeRender! mamma mia, thank you, solved :slight_smile:

1 Like

You can also avoid some meshes to be taken into account by scene.pickWithRay by passing a predicate to this function (2nd parameter) to only select the meshes you want to be tested with the ray.

2 Likes