olsibob

Can I pick a sprite with a ray?

Recommended Posts

I'm able to pick sprites with Scene.pickSprite, but is there a way to pick them with scene.pickWithRay? PickWithRay only seems to return meshes (I've set isPickable to true on the sprites and confirmed that they're pickable with Scene.pickSprite).

The use-case is, I'm trying to pick sprites with a 3DoF VR Controller, so I don't have a 2d pointerX and pointerY to work with, only the controller's forward ray.

I'm thinking that my options are:

a. Use Vector3.Project to try to unproject the pickedPoint of pickWithRay (I'm using a skybox, so the ray will always hit something), then put that point into Scene.pickSprite. I tried this quickly, but I think the unprojected point might be off

b. replace the sprites with billboarded mesh instances that can directly be hit with pickWithRay. I suspect this might be the easiest option?

Or is there some easier way to pick a sprite with a ray?

Share this post


Link to post
Share on other sites

Wow that was fast! Do you know if it's possible to try this out using npm? I thought I'd be able to do repo#commit:

"dependencies": {

"babylonjs": "git+https://github.com/BabylonJS/Babylon.js.git#685b8f0f4babca6fa1fef13f24991f5cafa107d8"

But the new method doesn't seem to be included

Share this post


Link to post
Share on other sites

If you are really keen, you can build it yourself from source to get latest.  Just clone or download, run npm install, and a gulp task
https://doc.babylonjs.com/how_to/how_to_start#gulp
You can use npm link or copy to your node_modules once built.  Only if you can't wait till Friday!  I would imagine it's in the playground already, though...  :)

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.