Jump to content

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.


Link to comment
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

Link to comment
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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...