我正在嘗試根據控制器上的搖桿輸入旋轉物件,然后將其夾在最大旋轉處。當我使用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);
}
任何幫助是極大的贊賞。
uj5u.com熱心網友回復:
試試這個東西
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);
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/410966.html
標籤:
上一篇:訪問Task<Token>.Result時Unity引擎凍結
下一篇:防止相機離開地形
