2D Mouse Aiming on Unity 4.3

Can anyone teach me how to perform a 2d mouse aiming on v4.3?

What do you mean by aiming? - Select objects under the cursor? - Spawn objects under the cursor? - Move the camera with the cursor? - ...?

an AIM pointer like in the METAL SLUG Series. The only problem is that when I try to shoot, the rocket is not on the location as the mouse pointer.

1 Answer

1

You have to get world coordinates from the screen coordinates of the mouse. This is done using the camera.

Vector2 characterPosition;
Vector3 3DmousePosition = camera.ViewportToWorldPoint(Input.mousePosition);
Vector2 2DmousePosition = new Vector2(3DmousePosition.x, 3DmousePosition.y);
Vector2 directionFromPlayerToMouse = (2DmousePosition - characterPosition).normalize;

Vector Math is "very" important in games. Be sure to study.

thanks! for the reply