コード例 #1
0
ファイル: CameraControl.cs プロジェクト: knightlyj/demo
    void UpdateLockedCamera()
    {
        //这里在距离过近,接近0时,会导致float为nan,不过正常情况下不会出现位置重叠,暂不处理
        Player    localPlayer = GlobalVariables.localPlayer;
        Player    target      = UnityHelper.GetLevelManager().GetPlayer(localPlayer.targetId);
        Transform aim         = target.GetComponent <CreatureCommon>().aim;
        Vector3   toTarget    = aim.position - watchPoint;
        float     targetPitch = -Mathf.Asin(toTarget.y / toTarget.magnitude) * Mathf.Rad2Deg;

        targetPitch += 15f;

        //镜头pitch范围限制
        if (targetPitch > maxPitch)
        {
            targetPitch = maxPitch;
        }
        else if (targetPitch < -maxPitch)
        {
            targetPitch = -maxPitch;
        }

        float targetYaw = CommonHelper.YawOfVector3(toTarget);

        float ratio = 0.08f * fixedCount;

        cameraYaw   = CommonHelper.AngleTowardsByDiff(cameraYaw, targetYaw, ratio, 0.01f);
        cameraPitch = CommonHelper.AngleTowardsByDiff(cameraPitch, targetPitch, ratio, 0.01f);

        //碰撞检测
        NormalViewCollide();
    }
コード例 #2
0
ファイル: CameraControl.cs プロジェクト: knightlyj/demo
    Vector3 noColPos;       //普通镜头,无碰撞时的位置
    void UpdateFreeCamera() //更新镜头角度
    {
        //按照无碰撞时的位置,计算镜头到玩家的角度,这样横向移动就会带动镜头旋转
        Vector3 toWatchPoint = watchPoint - noColPos;

        if (resetNormalCamera)
        {
            cameraYaw = CommonHelper.AngleTowardsByDiff(cameraYaw, resetYaw, Time.deltaTime * 5, 0.5f);
            if (cameraYaw == resetYaw)
            {
                resetNormalCamera = false;
            }
        }
        else
        {
            //计算从当前的无碰撞位置到player的yaw
            this.cameraYaw = CommonHelper.YawOfVector3(toWatchPoint);

            UpdateInput();
        }
        //碰撞检测
        NormalViewCollide();
    }