Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR 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
    }
Source by www.fxp.co.il #
 
PREVIOUS NEXT
Tagged: #Unity #rotate #player #mouse #point #slowly
ADD COMMENT
Topic
Name
3+2 =