一种摄像机跟随方式

xiaoxiao2021-02-28  11

//控制玩家移动的方法 通过 CharacterController

Update()/EasyJoystick OnMove()

vec.x/vec.y为玩家输入

Vector3 direction = new Vector3(vec.x, 0, vec.y);                 direction = Camera.main.transform.TransformDirection(direction);                 direction.y = 0;                 direction *= speed;                 characterController.Move(direction * Time.deltaTime);                     if (vec.x != 0 || vec.y != 0)                     {                         this.transform.rotation =                             Quaternion.Slerp(this.transform.rotation, Quaternion.LookRotation(new Vector3(direction.x, 0, direction.z)), smooth);                     }

//摄像机跟随 通过向量来计算摄像机位置

Update()

        Camera.main.transform.position = Vector3.Lerp(Camera.main.transform.position,             targetPos.position + targetPos.up * distanceUp - targetPos.right * distanceLeft + camQuaternion * -Vector3.forward * distanceAway, lerpSpeed);         Camera.main.transform.rotation = Quaternion.Slerp(Camera.main.transform.rotation, camQuaternion, lerpSpeed);

//滑动UI更改摄像机视野 

OnDrag()

  float x_Value = Input.GetAxis("Mouse X");         float y_Value = Input.GetAxis("Mouse Y");         X += x_Value * camRotateSpeed;         Y += -y_Value * camRotateSpeed;         Y = Mathf.Clamp(Y, -10, 20);         var rot = Quaternion.Euler(Y, X, 0);         CameraMove.Instance.RotateCam(rot); //修改摄像机脚本的camQuaternion

转载请注明原文地址: https://www.6miu.com/read-200067.html

最新回复(0)