如何在Unity3D中夹相机?

问题描述 投票:0回答:2

我试过这个,但每当我按下显示器时,相机都会从这一点开始。 所以我现在不知道该怎么做

我试图用钳子做一些,但它出错了

if(Input.GetTouch(0).phase == TouchPhase.Began ) 
{
    firstpoint = Input.GetTouch(0).position;
    ???xAngTemp = Mathf.Clamp(xAngle, 10, 10);
    ???yAngTemp = Mathf.Clamp (yAngle, 10, 10);
    xAngTemp = xAngle;
    yAngTemp = yAngle;
}

if(Input.GetTouch(0).phase==TouchPhase.Moved) 
{
    secondpoint = Input.GetTouch(0).position;
    ???xAngTemp = Mathf.Clamp(xAngle, 10, 10);
    ???yAngTemp = Mathf.Clamp (yAngle, 10, 10);

    //Mainly, about rotate camera. For example, for Screen.width rotate on 180 degree
    xAngle = xAngTemp + (secondpoint.x - firstpoint.x) * 30 * XSensitivity / Screen.width;
    yAngle = yAngTemp - (secondpoint.y - firstpoint.y) * 15 * YSensitivity / Screen.height;

    //Rotate camera
    this.transform.rotation = Quaternion.Euler(yAngle, xAngle, 0.0f);
}
c# unity3d
2个回答
0
投票

我很愚蠢要修复水平旋转,应该删除yClamp)))非常感谢所以rotX = Mathf.Clamp(rotX,-90f,90f);实际上工作我只是愚蠢,香港专业教育学院没有 - 运营商第一)


0
投票

首先是一个名为RotSpeed的速度变量:

float RotSpeed = 1; 

然后修改你的更新功能,如下所示:

rotX += Input.touches[0].deltaPosition.x * RotSpeed;
rotY += Input.touches[0].deltaPosition.y * RotSpeed;
rotX = Mathf.Clamp(rotX, -90f, 90f);
rotY = Mathf.Clamp(rotY, -90f, 90f);
Camera.main.transform.Rotate(Vector3.up, rotX * 5, Space.Self);
Camera.main.transform.Rotate(Vector3.left, rotY * 5, Space.Self);
© www.soinside.com 2019 - 2024. All rights reserved.