Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

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);
Comment

PREVIOUS NEXT
Code Example
Csharp :: emboss button in android app 
Csharp :: += meaning c# 
Csharp :: c# datetimepicker set weeks before today 
Csharp :: c# list join 
Csharp :: destroy gameobject unity 
Csharp :: traversing an enum c# 
Csharp :: How to read a XML on C# 
Csharp :: what type of variable is true or false in c# 
Csharp :: c# string to enum conversion 
Csharp :: C# How to change the text colour? 
Csharp :: DateTime previous day c# 
Csharp :: unity hide in inspector 
Csharp :: public GameObject 
Csharp :: how consider the first caracter in Split c# 
Csharp :: how to change textMesh Pro unity 
Csharp :: delayed function unity 
Csharp :: how to execute linux command from c# 
Csharp :: c# get class name by type 
Csharp :: unity button press onclick click add C# 
Csharp :: unity random 
Csharp :: unity check if a animator parameter trigger is activated 
Csharp :: 2d game art 
Csharp :: c# string.join 
Csharp :: placeholder syntax c# 
Csharp :: unity new input system keydown 
Csharp :: enum element count C# 
Csharp :: c# compress string 
Csharp :: c# join string array 
Csharp :: list all files in directory and subdirectories c# 
Csharp :: random.range unity not working 
ADD CONTENT
Topic
Content
Source link
Name
5+6 =