Answers for "use rotation of gameobject to control mouse position unity"

C#
1

rotation facing mouse unity

//Rotate Object to face Mouse (2D, Rotate on Z-Axis)

Vector3 pos = Camera.main.WorldToScreenPoint(transform.position);
Vector3 dir = Input.mousePosition - pos;
float angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
Posted by: Guest on January-16-2021

Code answers related to "use rotation of gameobject to control mouse position unity"

C# Answers by Framework

Browse Popular Code Answers by Language