角色模型在相机中偏移显示

1.实现角色模型展示中,模型位置偏于中轴线,并且拉近拉远,旋转的过程中,模型位置相对于屏幕不变 。

实现方式:正常情况,相机正对目标点,角色模型会位于相机视野正中心,因此将相机设置成原始旋转的子物体,并有一定偏移,则模型在相机视野中将会偏移。

初始相机偏移距离的确定,首先在UI面板中设置两个点,一个是UI中心点,一个是模型展示位置点,两者纵坐标相同,根据UI中两个坐标点,以UI摄像机先转化为屏幕坐标(uiCamera),再以相机就位后距离目标点距离转化为世界坐标(mainCamera)。

Vector3 showModelScreenPos = uiCamera.WorldToScreenPoint(rect1.transform.position);
           
Vector3 centerScreenPos = uiCamera.WorldToScreenPoint(rect2.transform.position);
            
            
Vector3 showModelWorldPos = GetMainCamera().ScreenToWorldPoint(new Vector3(showModelScreenPos.x, showModelScreenPos.y, 
          CameraConstData.MaxZoomFocusInitDistance));
            
            
Vector3 centerWorldPos = GetMainCamera().ScreenToWorldPoint(new Vector3(centerScreenPos.x, centerScreenPos.y, 
                CameraConstData.MaxZoomFocusInitDistance));
            
            
float cameraOffset = Vector3.Distance(showModelWorldPos, centerWorldPos);
            
            
GetMainCamera().fieldOfView = CameraConstData.DefaultFOV;//设置完offset再将相fov还原

 根据相机初始偏移,初始距离目标点距离确定角度,之后相机前后拉近拉远过程中动态调整相机偏移大小

 相机前后拉近拉远的过程中,相机目标点需要上下移动,以保证相机距离最远时目标点下移以保证整个模型出镜,相机拉近后,目标点上移,以锁定玩家上半身头部

猜你喜欢

转载自blog.csdn.net/l17768346260/article/details/119615583