镜头旋转问题

1 reply [最后一篇]
thmyjukilop
User offline. Last seen 5 周 6 天 ago. Offline
Joined: 07/23/2010
Points: 25

按右键镜头旋转完之后会停在一个地方

怎么解决第二次按右键画面在上一个角度的问题?

 

// The target we are following

 

var target : Transform;

 

// The distance in the x-z plane to the target

 

var distance = 10.0;

 

// the height we want the camera to be above the target

 

var height = 5.0;

 

// How much we

 

var heightDamping = 2.0;

 

var rotationDamping = 3.0;

 

var sensitivityX : float = 15;

 

var sensitivityY : float = 15;

 

var minimumX : float= -360;

 

var  maximumX : float = 360;

 

var  minimumY : float = -60;

 

var  maximumY : float = 60;

 

var rotationX : float = 0;

 

var  rotationY : float = 0;

 

var originalRotation : Quaternion ;

 

function Start ()

 

    {

 

        // Make the rigid body not change rotation

 

        if (rigidbody)

 

            rigidbody.freezeRotation = true;

 

        originalRotation = transform.localRotation;

 

    }

 

    

 

function ClampAngle (angle : float, min : float , max : float)

 

    {

 

        if (angle < -360)

 

            angle += 360;

 

        if (angle > 360)

 

            angle -= 360;

 

        return Mathf.Clamp (angle, min, max);

 

    }

 

// Place the script in the Camera-Control group in the component menu

 

@script AddComponentMenu("Camera-Control/Smooth Follow")

 

function FixedUpdate () {

 

            //transform.Translate(Vector3.right * Time.deltaTime, Camera.main.transform);

 

            if (Input.GetButton("Fire2")&&(Mathf.Abs(Input.GetAxis("Horizontal")) == 0 ) ){

 

                

 

                rotationX += Input.GetAxis("Mouse X") * sensitivityX;

 

                rotationX =     ClampAngle (rotationX, minimumX, maximumX);

 

                var xQuaternion : Quaternion ;

 

                 xQuaternion = Quaternion.AngleAxis (rotationX, Vector3.up);

 

                transform.localRotation = originalRotation * xQuaternion;

 

                

 

                }

 

            

 

        }

 

function LateUpdate () {

 

    // Early out if we don't have a target

 

    if (!target)

 

        return;

 

    

 

    // Calculate the current rotation angles

 

    wantedRotationAngle = target.eulerAngles.y;

 

    wantedHeight = target.position.y + height;

 

        

 

    currentRotationAngle = transform.eulerAngles.y;

 

    currentHeight = transform.position.y;

 

    

 

    // Damp the rotation around the y-axis

 

    currentRotationAngle = Mathf.LerpAngle (currentRotationAngle, wantedRotationAngle, rotationDamping * Time.deltaTime);

 

    // Damp the height

 

    currentHeight = Mathf.Lerp (currentHeight, wantedHeight, heightDamping * Time.deltaTime);

 

    // Convert the angle into a rotation

 

    currentRotation = Quaternion.Euler (0, currentRotationAngle, 0);

 

    

 

    // Set the position of the camera on the x-z plane to:

 

    // distance meters behind the target

 

    transform.position = target.position;

 

    transform.position -= currentRotation * Vector3.forward * distance;

 

    // Set the height of the camera

 

    transform.position.y = currentHeight;

 

    

 

    // Always look at the target

 

    transform.LookAt (target);

 

}

uke
User offline. Last seen 6 小时 48 分钟 ago. Offline
Joined: 09/07/2009
Points: 2660

没弄明白你说的意思,不过你可以参照官方的一个室内演示的例子,里面有相机旋转的功能!