Hello,
i have a working rotate to cursor script for my 2d game but it is 90 degrees off e.g. when the cursor is at the top of the screen the ship is pointing left.
Code:
function Update () {
var mousePos = Input.mousePosition;
var lookPos : Vector3 = Camera.main.ScreenToWorldPoint(mousePos);
lookPos = lookPos - transform.position;
var angle : float = Mathf.Atan2(lookPos.y, lookPos.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
}
Thanks,
Joseph