如何设置范围以进行上下摄像机摩擦

发布于 2025-02-11 03:47:14 字数 975 浏览 1 评论 0原文

我正在用拼字摄像头制作游戏,该摄像机假设扭转播放器并在鼠标上上下移动。问题是我找不到一种为向上和向下移动的范围的方法,只能以小角度上下移动 这是我的代码

void LateUpdate () {

if (Input.GetMouseButtonDown(0))
{

    RotateAroundPlayer = true;


}
else if (Input.GetMouseButtonUp(0))
{
    RotateAroundPlayer = false;
}

if (RotateAroundPlayer)
{
    Quaternion camTurnAngle =
        Quaternion.AngleAxis(Input.GetAxis("Mouse X") * RotationsSpeed, Vector3.up);
    Quaternion camUpDown =
        Quaternion.AngleAxis(Input.GetAxis("Mouse Y") * RotationsSpeed, transform.right);
   
    _cameraOffset = camUpDown * camTurnAngle * _cameraOffset;
    
}
Vector3 newPos = PlayerTransform.position + _cameraOffset;
transform.position = Vector3.Slerp(transform.position, newPos, SmoothFactor);

if (LookAtPlayer || RotateAroundPlayer)
    transform.LookAt(PlayerTransform);

}

我尝试添加下面的代码,但是相机赢了,它达到了最小值

    _cameraOffset.y = Mathf.Clamp(_cameraOffset.y,  minViewingAngle,maxViewingAngle);

I am making a game with an orthographic camera, the camera suppose to turn around the player and move up and down on mouse hold. The problem is that I can't find a way to make a range for the up and down movement, it is only supposed to go up and down for just a small angle
this is my code

void LateUpdate () {

if (Input.GetMouseButtonDown(0))
{

    RotateAroundPlayer = true;


}
else if (Input.GetMouseButtonUp(0))
{
    RotateAroundPlayer = false;
}

if (RotateAroundPlayer)
{
    Quaternion camTurnAngle =
        Quaternion.AngleAxis(Input.GetAxis("Mouse X") * RotationsSpeed, Vector3.up);
    Quaternion camUpDown =
        Quaternion.AngleAxis(Input.GetAxis("Mouse Y") * RotationsSpeed, transform.right);
   
    _cameraOffset = camUpDown * camTurnAngle * _cameraOffset;
    
}
Vector3 newPos = PlayerTransform.position + _cameraOffset;
transform.position = Vector3.Slerp(transform.position, newPos, SmoothFactor);

if (LookAtPlayer || RotateAroundPlayer)
    transform.LookAt(PlayerTransform);

}

I tried to add the code below but the camera win it reaches the minimum value it goes a way

    _cameraOffset.y = Mathf.Clamp(_cameraOffset.y,  minViewingAngle,maxViewingAngle);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文