Jump to content

Pick at ground level


joshcamas
 Share

Recommended Posts

Hi guys!

I'm workin on a little isometric test, and I'm a little unsure how to do something.

specifically, I want to detect which tile was clicked when I press my mouse down.

One way could be to make a flat plane the size of the world, and pick from that... but that sounds ridiculous.

 

Is it possible to translate a 2D position on screen (mouse) to a 3D position, if you know that the Y value is 0?
So I just need the X and Z 3D coordinates. 

Thanks a bunch! 

Link to comment
Share on other sites

Hi @joshcamas

Good to see you on the forum again. I haven't been on in some time, but will be again soon. I hope I understand your question, as this is a fairly common process. I simply modified an existing PG scene to return the pick point to the console log.

http://www.babylonjs-playground.com/#12ZRI0#5

If I mis-understood the question, please let me know.

DB

Link to comment
Share on other sites

3 hours ago, dbawel said:

Hi @joshcamas

Good to see you on the forum again. I haven't been on in some time, but will be again soon. I hope I understand your question, as this is a fairly common process. I simply modified an existing PG scene to return the pick point to the console log.

http://www.babylonjs-playground.com/#12ZRI0#5

If I mis-understood the question, please let me know.

DB

Thanks my friend! I was hoping to get a position without a ground mesh, though. So not picking, I guess? 

Like it would be as if there was a ground mesh... since I'll always pick at Y = 0. But having a massive mesh the size of a big world sounds tedious, so if possible I'd like to skip that ^_^

Nice to see ya too, good to see some familiar faces!

 

 

Link to comment
Share on other sites

9 hours ago, Kesshi said:

This is what i'm doing:
http://www.babylonjs-playground.com/#1BGF1O#1
I create a ray and a mathematical plane and compute the intersection. This is much faster compared to the geometrical picking.

A AHHHHH there we go! That looks like exactly what I'm looking for! Thanks a bunch mate!!! 

Link to comment
Share on other sites

Thanks @Kesshi! I've implemented your solution as well.

https://github.com/chad-autry/hex-grid-map-3D/commit/d888fe0d32b15cfd9e25c0348549238731f6396b#diff-dda223dd45fb162ee094a143a42d7006

Ignore the deletes of gh-pages I had to messily recover from....

 

As you might see my former solution was to make an invisible finite picker plane, which I had to move around as my camera moved so I didn't go off the end.

Performance wise I don't have any metrics showing the change was required. Using scene.pick was fast enough. However, Kesshi's way has fewer moving parts, and is how I would have wanted to do it in the first place if I'd known.

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.

Guest
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.

Loading...
 Share

  • Recently Browsing   0 members

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