# Covert screen coordinates to World's x and y

## Recommended Posts

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!

##### Share on other sites

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.

##### Share on other sites

@RaananW, how would you deal with camera's position/rotation in this case? Can you provide an example? Even pseudo-code will do

##### Share on other sites

Why pseudo, when you can get the real thing:

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

##### Share on other sites

You're da man, @RaananW! Will give it a try.

##### Share on other sites

@RaananW, thanks again, dude! This worked like a dream

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

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.