Answers for "how to make a object rotate towards a position in 2d unity"

C#
2

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));
Posted by: Guest on December-31-2020

Code answers related to "how to make a object rotate towards a position in 2d unity"

C# Answers by Framework

Browse Popular Code Answers by Language