- Home /
Unity 2d jittery gameobject rotation
What i am trying to do is make an object look at the mouse, but for some reason it kinda glitches if the object moves by itself.
var dir = Input.mousePosition - Camera.main.WorldToScreenPoint(transform.position);
var angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
Comment