distraub

Having an issue with Ray.intersectsMesh

Recommended Posts

I am hoping someone can take a look at this, and let me know if I am using it wrong.

I have 2 spheres that I have attached Rays to, they are both shooting at a target, and there is a large sphere in the way, called earth.

When I change the position of the spheres, the pickedPoint that is returned by hitInfo on the Ray.intersectsMesh function seems to be giving me an incorrect Picked Point if my source has a negative Y position.

The "source" ray is just fine, but the "alternate" ray seems to be getting a picked point that is on the wrong side of the earth.

Any help would be appreciated, I put this in a playground so you can see what I mean.

https://www.babylonjs-playground.com/#KNB069

Share this post


Link to post
Share on other sites

Hello Distraub !

I did some test with your PG.

  • First thing I can say is that even with a negative Y position, the picked point may be the one you are looking for : https://www.babylonjs-playground.com/#KNB069#1
  • When using pickWithRay method instead of intersectWithMesh, even with not-working-Y-position on your alternate sphere, it is working as expected. I think it is because pickWithRay get the first hit from source to target while intersectWithMesh has another behaviour : https://www.babylonjs-playground.com/#KNB069#2

Hope it will help

Share this post


Link to post
Share on other sites

Thank you @Amarth2Estel

This does solve my issue, if I use multiPickWithRay and then check for the id of my mesh, then it works as expected.

I was hoping intersectsMesh would work the same way.

Here is an example https://www.babylonjs-playground.com/#KNB069#3

If you intersectsMesh with those coordinates it seems to use the other end, which almost looks like it is shooting the ray from the target to the source and using that picked point.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.