Raycast not hitting on imported mesh

Hey all! I’m working with raycast and got a issue that my raycast is not colliding with my mesh. The mesh I’m trying to collide is a imported .babylon file and the raycast simply don’t collide with it.

I tested with a simple box and then the collide worked, just not sure what should I do to debug it and make the raycast to work, does anyone has any ideas of how to fix that?

Heres the playground: https://playground.babylonjs.com/#YIU90M#1337

cc @Cedric

weird indeed. Any idea @Evgeni_Popov ? otherwise, I’ll have to start debugging :slight_smile:

https://playground.babylonjs.com/#YIU90M#1338 calling computeWorldMatrix will help

2 Likes

Interesting!

But why thi is needed in my case @sebavan? I mean is it something that I messed up with my mesh?

I wanted to know what happened if possible cause I saw a lot of situations that the mesh don’t needed that computeWorldMatrix and wanted to understand why its needed in my case :thinking:

It is not smthg you messed up it is just that after loading there are a few operations that happens during the render which did not happen yet so you need to call it manually.

1 Like

Now I’m curious, add the raycast on the a beforeRenderObservable worked!

But the fact is that on my project its not working even creating the ray on the beforeRenderObservable, does that computeWorldMatrix happens on each render observable?

On my project here it don’t work even with the computeWorldMatrix :confused:

Can you take a look on it?: GitHub - Alecell/babylon-2.5d

I add the raycast on this file src/utils/physics/physics.ts

Would be great to repro in the playground, we can not clone/run all the projects locally unfortunately. We usually do it in case of build failure. Even more as your project is pretty big already.

Could you add in the playground the missing part that would make it fail ? so that we can find a fix

1 Like

Hey @sebavan!

I added it on the playground as you suggested!

Its pretty big code as you said, but the place where I add the Ray is on the Physics class on the applyPhysics method.

Just a little explanation of whats going on, the whole point about that Physics is that its a property of the Prefab abstract class that each of my “prefabs” implements, so basically both the Ground and Player has the physics that use that raycast, the issue is on the Player Ray that’s not hitting the Ground mesh. Also on that applyPhysics method I added that computeWorldMatrix but the behavior is the same :confused:

Thats the playground: https://playground.babylonjs.com/#YIU90M#1342

Thank you for your time helping me with that btw :smile:

Pickable of loaded model is false. That must be the reason.

image

this.scene.meshes.forEach((m) => { m.isPickable = true; });

4 Likes

It worked!

Thank you @11128!

1 Like