joshcamas Posted January 30, 2017 Share Posted January 30, 2017 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! Quote Link to comment Share on other sites More sharing options...
dbawel Posted January 30, 2017 Share Posted January 30, 2017 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 Quote Link to comment Share on other sites More sharing options...
joshcamas Posted January 30, 2017 Author Share Posted January 30, 2017 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! Quote Link to comment Share on other sites More sharing options...
Kesshi Posted January 30, 2017 Share Posted January 30, 2017 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. joshcamas, chadautry and jpdev 3 Quote Link to comment Share on other sites More sharing options...
joshcamas Posted January 30, 2017 Author Share Posted January 30, 2017 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!!! Quote Link to comment Share on other sites More sharing options...
joshcamas Posted January 31, 2017 Author Share Posted January 31, 2017 Ok... looks like when I use target camera, it throws an error. Why is this? http://www.babylonjs-playground.com/#1BGF1O#2 EDIT: Alright, I just ended up using arcRotateCamera instead, and it works like a charm. Thanks so much! GameMonetize 1 Quote Link to comment Share on other sites More sharing options...
chadautry Posted February 1, 2017 Share Posted February 1, 2017 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. Quote Link to comment Share on other sites More sharing options...
Nabroski Posted February 1, 2017 Share Posted February 1, 2017 http://www.babylonjs-playground.com/#1BGF1O#3 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.