相机的跟随(一)

相机总是在角色背后distanceAway距离处,且在角色头顶上方distanceUp的高度上

相机的跟随(一)_第1张图片

  public Transform player;
    public float distanceUp = 2f;
    public float distanceAway = 5f;
    public float smooth = 1f;
    private Vector3 targetPos;

    void Awake()
    {
        player = GameObject.FindGameObjectWithTag("Player").transform;
    }

    void LateUpdate()
    {
        targetPos = player.position + distanceUp * Vector3.up - player.forward * distanceAway;
        transform.position = Vector3.Lerp(transform.position, targetPos, Time.deltaTime * 5f);
        transform.LookAt(player);
    }

 

你可能感兴趣的:(Camera跟随,unity基础)