- Home /
Question by
Reedex · Apr 20, 2018 at 10:39 AM ·
2doffsetmouse input
Hi, i'm having weird offset on mouse input, could someone explain why this happens please? (i don't think its code issue, tried many , all work, but with offset)Pictures and code below anyway .Thanks.
void Update()
{
Vector2 direction = Camera.main.ScreenToWorldPoint (Input.mousePosition) - transform.position;
float angle = Mathf.Atan2 (direction.y, direction.x) * Mathf.Rad2Deg;
Quaternion rotation = Quaternion.AngleAxis (angle, Vector2.up);
transform.rotation = Quaternion.Slerp (transform.rotation, rotation, 3 * Time.deltaTime);
}
}
mouse-offset.png
(8.1 kB)
Comment
Best Answer
Answer by Harinezumi · Apr 20, 2018 at 11:01 AM
Is the crosshair a custom cursor? In that case, you might need to set the hotspot of the cursor sprite to the center of the image, because (if I remember correctly) (0, 0) of the cursor is the upper left corner. You can even do it from code, see this answer.
hh, i am using two crosshairs, one a hand with a pointed finger, and a aimer,...the pointed finger worked fine cuz the finger pointing to left top corner. the other one didn't . now i divided by two the image size hotspot and voila.... THAN$$anonymous$$S.bugged me for some time.