unity 2d rotate object towards position code example
Example: how to make a object rotate towards a position in 2d unity
Vector3 targ = staticCompassTarget.transform.position;
targ.z = 0f;
Vector3 objectPos = transform.position;
targ.x = targ.x - objectPos.x;
targ.y = targ.y - objectPos.y;
float angle = Mathf.Atan2(targ.y, targ.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.Euler(new Vector3(0, 0, angle));