Esempio n. 1
0
    void Update()
    {
        float dtheta = Input.GetAxisRaw("Camera Horizontal");
        float dy     = Input.GetAxisRaw("Camera Vertical");

        if (Input.GetButton("Run"))
        {
            cameraBehavior = runCamera;

            // calculate the forward directions of the camera and what it's
            // following, projected onto the xz-plane

            var camForward = Vector3.ProjectOnPlane(
                transform.rotation * Vector3.forward, Vector3.up
                );
            var followForward = Vector3.ProjectOnPlane(
                following.rotation * Vector3.forward, Vector3.up
                );

            // calculate the angle between the two forward directions
            // in order to tell the camera how to rotate toward the direction
            // of the object it's following

            dtheta = Vector3.Angle(camForward, followForward) / 180f;
            var cross = Vector3.Cross(camForward, followForward);
            if (dtheta < 0.1f)
            {
                dtheta = 0f;
            }
            else if (Vector3.Dot(cross, Vector3.up) < 0f)
            {
                dtheta = -dtheta;
            }
        }
        else
        {
            cameraBehavior = walkCamera;
        }

        cameraBehavior.Update(this, dtheta, dy);
        transform.position = following.position + this.DifferenceFromTarget();
        transform.LookAt(following);
    }
Esempio n. 2
0
 public virtual void Update(float elapsed)
 {
     _cameraBehavior.Update(elapsed);
 }
Esempio n. 3
0
 public override void Update(float elapsed)
 {
     _cameraBehavior.Update(elapsed);
 }