x


World position of a mouse click with a tilted camera

In this 2D (2.5d?) scene, I have a camera at 0,-20,-25 and tilted along its x-axis to 310 degrees. I'd like to be able properly get the XY coordinates of a mouse click to eventually move the player to that point.

At certain points, where the user clicks is actually a non-intuitive world position due to the tilted camera, usually with Y movements. So the actual world position would be quite a bit off from where they clicked.

Any advice on handling this sort of situation? My current code is below, but not very intuitive.

        Vector3 dest = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0));
        dest.y -= Camera.main.transform.position.y;

For example: http://www.youtube.com/watch?v=Wg3DRwPsd0g

That looks like a 2.5d camera, but they somehow have the ship go to where the player clicks.

more ▼

asked Feb 18 '11 at 07:37 PM

spaceshooter gravatar image

spaceshooter
249 49 55 69

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first
more ▼

answered Feb 18 '11 at 11:38 PM

spaceshooter gravatar image

spaceshooter
249 49 55 69

(comments are locked)
10|3000 characters needed characters left
more ▼

answered Feb 18 '11 at 09:39 PM

DaveA gravatar image

DaveA
26.4k 151 171 256

That was certainly part of the fix, thanks!

Feb 18 '11 at 11:39 PM spaceshooter
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x982
x884
x109

asked: Feb 18 '11 at 07:37 PM

Seen: 2585 times

Last Updated: Feb 18 '11 at 08:28 PM