- Home /
Use the mouse to aim?
Use the mouse to aim? I want to do as Shooting in this game: http://www.hrajuhry.cz/strilecky/hra/outposthaven#hra (sorry for my english, i am from the Czech republic and google translator is really bad :D )
Comment
Answer by Crispinator · Aug 22, 2013 at 10:32 PM
Just insert in a first person controller. Attach your firearm prefab to the main camera.
Answer by robertbu · Aug 23, 2013 at 05:37 AM
Assuming:
Top down view
Camera parallel to the XZ plane
Model built so that 'forward' is facing positive 'Z' when rotation is (0,0,0)
Something like this will work:
#pragma strict
function Update() {
var pos = Vector3(Input.mousePosition.x, Input.mousePosition.y, Camera.main.transform.position.y - transform.position.y);
pos = camera.main.ScreenToWorldPoint(pos);
var aimingDirection = pos - transform.position;
transform.rotation = Quaternion.LookRotation(aimingDirection);
}