Beispiel #1
0
    void Turn()
    {
        if (InputManager.inputType == InputType.Controller)
        {
            Vector3 NextDir = new Vector3(ControllerInputManager.GetRightStickHorizontal(), 0, ControllerInputManager.GetRightStickVertical());
            if (NextDir != Vector3.zero)
            {
                Quaternion newRotation = Quaternion.LookRotation(NextDir);
                transform.rotation = Quaternion.RotateTowards(transform.rotation, newRotation, 1400f * Time.deltaTime);
            }
        }

        if (InputManager.inputType == InputType.KeyboardMouse)
        {
            // Treffer vom Raycast
            RaycastHit hit;
            //Ray von der Mausposition
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            if (Physics.Raycast(ray, out hit, 100, floorMask))
            {
                // Erstellung des Vektor, der von der Spieler Position bis zu dem Punkt zeigt, den die Maus auf der Maske getroffen hat
                Vector3 playerToMouse = hit.point - transform.position;

                // Sicherstellen, dass der Vektor parallel zum Boden ist.
                playerToMouse.y = 0f;

                // Rotation erstellen
                Quaternion newRotation = Quaternion.LookRotation(playerToMouse);

                // neue Roataion übergeben
                transform.rotation = Quaternion.RotateTowards(transform.rotation, newRotation, 1200f * Time.deltaTime);
            }
        }
    }