- Home /
Question by
coolfireking2 · Dec 30, 2013 at 09:04 PM ·
rotationmousecursor
Rotate to mouse cursor error
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
Comment
Answer by robertbu · Jan 01, 2014 at 07:52 AM
The easiest solution is to just rotate your texture, but you can modify the angle:
transform.rotation = Quaternion.AngleAxis(angle-90.0, Vector3.forward);
Your answer
Follow this Question
Related Questions
Screen.lockCursor messes my rotation 1 Answer
Flight Sim Mouselook 1 Answer
'Camera' does not contain a definition for 'ScreenPointToRay' 1 Answer
Why does only the first of sequential quaternion operations work? 1 Answer
Touch mouseorbit 5 Answers