max123 Posted November 17, 2016 Share Posted November 17, 2016 Hi, I've searched the forum, but most questions and answers that I found relate to the reverse: convert World to Screed coordinates. The reason I need this is to launch a projectile in the direction of mouse coordinates when a user clicks on a screen. I tried the ray picking approach, but 1) it's too cumbersome and it didn't work, and 2) there's nothing to pick with a ray! I wonder if anyone here had the same issue and managed to find a solution. Cheers! Quote Link to comment Share on other sites More sharing options...
RaananW Posted November 17, 2016 Share Posted November 17, 2016 Well, you are clicking in a 2D space, what would you expect to get? let's say your camera is parallel to the floor, pointer straight at the z axis. Let's say we have y (which is 0) and x (which is also 0). What would you expect Z to be? Picking is your friend (which is rather straight-forward). You will need to add a picking mesh (a plane, for example) that will transform your single click to 3d coordinates according to your definition. This would be the simplest way. Quote Link to comment Share on other sites More sharing options...
max123 Posted November 17, 2016 Author Share Posted November 17, 2016 @RaananW, how would you deal with camera's position/rotation in this case? Can you provide an example? Even pseudo-code will do Quote Link to comment Share on other sites More sharing options...
RaananW Posted November 17, 2016 Share Posted November 17, 2016 Why pseudo, when you can get the real thing: http://www.babylonjs-playground.com/#ALAAX wall is your collision wall, I set it's material's alpha to be 0.3 (so you will see where it is). the pick result is the position in the world that you clicked on. notice that the wall's parent is the camera, and that it is 20 units away from it, so this would be your z axis (local coordinates). max123 1 Quote Link to comment Share on other sites More sharing options...
max123 Posted November 17, 2016 Author Share Posted November 17, 2016 You're da man, @RaananW! Will give it a try. Quote Link to comment Share on other sites More sharing options...
max123 Posted November 17, 2016 Author Share Posted November 17, 2016 @RaananW, thanks again, dude! This worked like a dream RaananW 1 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.