Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

Unity rotate player to mouse point slowly

public float delay = 350; // The rotation speed
    void Update()
    {
        Vector2 diff = Camera.main.ScreenToWorldPoint(Input.mousePosition); //Gets the mouse Pos
        diff.Normalize();
        float rotateZ = Mathf.Atan2(-diff.x, diff.y) * Mathf.Rad2Deg;
       transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.Euler(0,0,rotateZ), delay * Time.deltaTime); //Sets the new rotation
    }
Comment

PREVIOUS NEXT
Code Example
Csharp :: get host ip address asp.net core 
Csharp :: compute months c# 
Csharp :: c# get next item in list 
Csharp :: unity know when gameobject presed 
Csharp :: c# json to dictionary 
Csharp :: c# get project directory 
Csharp :: unity flexiable space 
Csharp :: delay in unity 
Csharp :: taking input in single line c# 
Csharp :: messagebox.show c# error 
Csharp :: how to create a new folder with c# 
Csharp :: loadscene unity 
Csharp :: unity conditional field 
Csharp :: unity get direction from one point to another 
Csharp :: how to get all panels in form in c# 
Csharp :: unity button addlistener 
Csharp :: winforms messagebox with button 
Csharp :: how to say "Hello world" in c# 
Csharp :: restart animation unity 
Csharp :: check internet connection in c# 
Csharp :: Codewars Multiply 
Csharp :: textbox only numbers c# 
Csharp :: c# get path without filename 
Csharp :: unity destroy self 
Csharp :: c# start process and wait for exit code 
Csharp :: convert dto to dictionary c# 
Csharp :: exit programm c# 
Csharp :: built in methods to order a list c# 
Csharp :: http error 502.5 asp.net core 2.2 
Csharp :: transformar de string a int c# 
ADD CONTENT
Topic
Content
Source link
Name
5+1 =