【发布时间】:2022-01-13 19:53:25
【问题描述】:
我正在尝试根据控制器上的摇杆输入旋转对象,然后将其夹在最大旋转位置。当我使用Mathf.Clamp() 时,旋转刚好碰到那面墙,感觉不太好。我也尝试过使用Mathf.SmoothDamp(),这会产生类似的结果。有没有办法在考虑摇杆输入的同时平滑地接近最大旋转角度?
void Update()
{
SmoothRotate();
}
void SmoothRotate()
{
rotateX += iR.leftStickY * rotationSensitivity * Time.deltaTime;
rotateX = Mathf.Clamp(rotateX, -maxPitchAngle, maxPitchAngle);
currentRotX = Mathf.Lerp(currentRotX, rotateX, .5f);
rotateZ += iR.leftStickX * rotationSensitivity * Time.deltaTime;
rotateZ = Mathf.Clamp(rotateZ, -maxPitchAngle, maxPitchAngle);
currentRotZ = Mathf.Lerp(currentRotZ, rotateZ, .5f);
transform.eulerAngles = new Vector3(currentRotX, currentAngle.y, currentRotZ);
}
非常感谢任何帮助。
【问题讨论】:
标签: c# unity3d smoothing lerp clamp