1 回答
TA贡献1826条经验 获得超6个赞
更新:试试这个
void LateUpdate()
{
if (lookAround)
{
currentX += Input.GetAxisRaw("Mouse X");
currentY += Input.GetAxisRaw("Mouse Y");
currentY = Mathf.Clamp(currentY, angleMinY, angleMaxY);
Vector3 dir = new Vector3(0, 0, -distance);
Quaternion rotation = Quaternion.Euler(currentY, currentX, 0);
Vector3 wantedPosition = target.position + rotation * dir;
transform.position = Vector3.Lerp(transform.position, wantedPosition, Time.deltaTime * damping);
camTransform.LookAt(target.position);
}
...
和
void Update()
{
// Here
if (Input.GetMouseButtonDown(1))
{
currentX = transform.eulerAngles.y;
currentY = transform.eulerAngles.x;
}
if (Input.GetMouseButton(1))
{
...
我所做的是在 Update() 中按下鼠标时将 currentX 和 currentY 重置为它们当前的欧拉角值。我在 LateUpdate() 中向想要的环视位置添加了一个位置 Lerp
编辑:
虽然我仍然没有修复最初按住鼠标右键时鼠标外观的平滑缩放
试试这个改变
void CameraOrbit()
{
currentX += Input.GetAxisRaw("Mouse X");
currentY += Input.GetAxisRaw("Mouse Y");
currentY = Mathf.Clamp(currentY, angleMinY, angleMaxY);
Vector3 dir = new Vector3(0, 0, -distance);
Quaternion rotation = Quaternion.Euler(currentY, currentX, 0);
// -->
Vector3 wantedPosition = target.position + rotation * dir;
transform.position = Vector3.Lerp(transform.position, wantedPosition, Time.deltaTime * damping);
// <--
camTransform.LookAt(target.position);
}
- 1 回答
- 0 关注
- 301 浏览
添加回答
举报