HeroCamera.Orbit C# (CSharp) 메소드

Orbit() 공개 메소드

public Orbit ( ) : void
리턴 void
    void Orbit()
    {
        // Desired distance via mouse wheel
        desDist -= Input.GetAxis ("Mouse ScrollWheel") * Time.deltaTime * zoomRate * Mathf.Abs (desDist);
        desDist = Mathf.Clamp (desDist, minDistance, maxDistance);
        finalDist = desDist;

        // Horizontal smooth rotation
        xAngl += Input.GetAxis ("Mouse X") * xSpeed * 0.02f;
        // Vertical angle limitation
        yAngl = ClampAngle (yAngl, minAngleY, maxAngleY);

        // Camera rotation
        Quaternion camRot = Quaternion.Euler (yAngl, xAngl, 0);
        // Camera height
        Vector3 headPos = new Vector3 (0, -heroHeight /1.2f, 0);
        // Camera position
        Vector3 camPos = hero.position - (camRot * Vector3.forward * desDist + headPos);

        // Recalculate hero position
        Vector3 trueHeroPos = new Vector3 (hero.position.x, hero.position.y + heroHeight, hero.position.z);

        // Check if there is something between camera and character
        RaycastHit hit;
        bool isOk = false;
        if ( Physics.Linecast (trueHeroPos, camPos, out hit, collisionLayers.value))
        {
            // Final distance
            finalDist = Vector3.Distance (trueHeroPos, hit.point) - offsetFromWall;
            isOk = true;
        }

        // Lerp current distance if not corrected
        if ( !isOk || ( finalDist > curDist ) )
            curDist = Mathf.Lerp (curDist, finalDist, Time.deltaTime * zoomDampening);
        else
            curDist = finalDist;

        // Clamp current distance
        //curDist = Mathf.Clamp (curDist, minDistance, maxDistance);

        // Recalculate camera position
        camPos = hero.position - (camRot * Vector3.forward * curDist + headPos);

        // Left shift = no y rotation
        if ( !Input.GetKey ( KeyCode.LeftShift ) )
        {
            // Apply Y-mouse axis
            yAngl -= Input.GetAxis ( "Mouse Y" ) * ySpeed * 0.02f;
        }

        // Apply position and rotation
        cam.rotation = camRot;
        cam.position = camPos;
    }