Unity rotate player to mouse point slowly

74

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
    }

Comments

Submit
0 Comments