如何平滑地钳制控制器输入?
How do I smoothly clamp controller input?
我正在尝试根据控制器上的操纵杆输入来旋转物体,然后将其固定在最大旋转位置。当我使用 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);
}
非常感谢任何帮助。
试试这个东西
public float mouseSensitivity = 10.0f;
public Transform target;
public float dstFromTarget = 2.0f;
public float yaw;
public float pitch;
public Vector2 pitchMinMax = new Vector2(-50, 85);
public float rotationSmoothTime = 0.02f;
Vector3 rotationSmoothVelocity;
Vector3 currentRotation;
void Update()
{
SmoothRotate();
}
void SmoothRotate()
{
//Mouse Movement
yaw += iR.leftStickX * mouseSensitivity;
pitch -= iR.leftStickY * mouseSensitivity;
// Clamp
pitch = Mathf.Clamp(pitch, -maxPitchAngle, maxPitchAngle);
transform.eulerAngles = Vector3.SmoothDamp(currentRotation, new Vector3(pitch, yaw), ref rotationSmoothVelocity, rotationSmoothTime);
}
我正在尝试根据控制器上的操纵杆输入来旋转物体,然后将其固定在最大旋转位置。当我使用 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);
}
非常感谢任何帮助。
试试这个东西
public float mouseSensitivity = 10.0f;
public Transform target;
public float dstFromTarget = 2.0f;
public float yaw;
public float pitch;
public Vector2 pitchMinMax = new Vector2(-50, 85);
public float rotationSmoothTime = 0.02f;
Vector3 rotationSmoothVelocity;
Vector3 currentRotation;
void Update()
{
SmoothRotate();
}
void SmoothRotate()
{
//Mouse Movement
yaw += iR.leftStickX * mouseSensitivity;
pitch -= iR.leftStickY * mouseSensitivity;
// Clamp
pitch = Mathf.Clamp(pitch, -maxPitchAngle, maxPitchAngle);
transform.eulerAngles = Vector3.SmoothDamp(currentRotation, new Vector3(pitch, yaw), ref rotationSmoothVelocity, rotationSmoothTime);
}