我希望能够在某一点之后限制相机旋转,并且只能在某个区域旋转,这是到目前为止的代码…@H_404_1@
@H_404_1@
void Update() {
float mouseX = Input.GetAxis("Mouse X");
float mouseY = -Input.GetAxis("Mouse Y");
rotY += mouseX * mouseSensitivity * Time.deltaTime;
rotX += mouseY * mouseSensitivity * Time.deltaTime;
desiredy = Camera.main.transform.eulerAngles.y;
desiredx = Camera.main.transform.eulerAngles.x;
if (!(desiredy < maxy && desiredy > miny))
{
//i dont kNow what to put in here, i have tried everything
}
else if (!(desiredx < maxx && desiredx > minx))
{
//i dont kNow what to put in here, i have tried everything
}
else
{
localRotation = Quaternion.Euler(rotX, rotY, 0.0f);
transform.rotation = localRotation;
}
}
你正在使你的不必要的逻辑变得复杂.您只需要Mathf.Clamp函数,以确保您的值在指定范围内.@H_404_1@
@H_404_1@
void Update()
{
rotateCamera();
}
public float xSensitivity = 100.0f;
public float ySensitivity = 100.0f;
public float yMinLimit = -45.0f;
public float yMaxLimit = 45.0f;
public float xMinLimit = -360.0f;
public float xMaxLimit = 360.0f;
float yRot = 0.0f;
float xRot = 0.0f;
void rotateCamera()
{
xRot += Input.GetAxis("Mouse X") * xSensitivity * Time.deltaTime;
yRot += Input.GetAxis("Mouse Y") * ySensitivity * Time.deltaTime;
yRot = Mathf.Clamp(yRot, yMinLimit, yMaxLimit);
Camera.main.transform.localEulerAngles = new Vector3(-yRot, xRot, 0);
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。