动画摄像机以转动玩家,然后继续跟踪玩家

Animating a camera to turn around the player, then continue tracking player

所以为了解释我想要实现的目标,我使用 "E" 键将摄像机围绕玩家旋转 90 度,然后继续跟踪玩家。我不知道如何顺利​​地做到这一点 - 到目前为止,我已经尝试过停止相机跟踪播放器的动画,以及动画完成后 return 回到原始位置的动画。

这是我当前的代码:

using UnityEngine;
using System.Collections;

public class TCam : MonoBehaviour {


    public Transform target;
    private Animator animator;
    private Vector3 positionOffset ;

    int i =0;
    // Use this for initialization
    void Start () {
        //positionOffset = target.transform.position + transform.position;
        positionOffset = new Vector3(-10, 10,0);
        animator = GetComponent<Animator> ();
        animator.enabled = true;
    }

    // Update is called once per frame
    void Update () {
        if (Input.GetKeyDown (KeyCode.E)) {
            animator.SetTrigger ("switch");

            transform.rotation = Quaternion.Euler (45, transform.rotation.eulerAngles.y + 90, 0);
            target.transform.rotation = Quaternion.Euler (45, target.transform.rotation.eulerAngles.y + 90, 0);

            if (i == 0) {
                positionOffset = new Vector3 (0, 10, 10);
                i++;
            } else if (i == 1) {
                positionOffset = new Vector3 (10, 10, 0);
                i++;
            } else if (i == 2) {
                positionOffset = new Vector3 (0, 10, -10);
                i++;
            } else if (i == 3) {
                positionOffset = new Vector3 (-10, 10, 0);
                i = 0;
            }
        } else if (Input.GetKeyDown (KeyCode.Q)) {
            transform.Rotate (-45, 0, 0);
            transform.Rotate (0, -90, 0);
            transform.Rotate (45, 0, 0);

            target.transform.Rotate (-45, 0, 0);
            target.transform.Rotate (0, -90, 0);
            target.transform.Rotate (45, 0, 0);
        }
        transform.position = target.position + positionOffset;
    }
}

不用四元数设置,尝试使用 Transorm.RotateAround() 方法如下:

transform.RotateAround(target.transform.position, Vector3.up, 40 * Time.deltaTime);

有条件在超过原始旋转 90 度时停止。同样,向后工作以将其移回。

希望对您有所帮助!