- Home /
2D Mouse Aiming on Unity 4.3
Can anyone teach me how to perform a 2d mouse aiming on v4.3?
Comment
What do you mean by ai$$anonymous$$g?
Select objects under the cursor?
Spawn objects under the cursor?
$$anonymous$$ove the camera with the cursor?
...?
an AI$$anonymous$$ pointer like in the $$anonymous$$ETAL SLUG Series. The only problem is that when I try to shoot, the rocket is not on the location as the mouse pointer.
Best Answer
Answer by Spinnernicholas · Nov 27, 2013 at 04:39 PM
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 $$anonymous$$ath is "very" important in games. Be sure to study.