[英]Why is my Unity object rotation being limited?
public class cameraRotation : MonoBehaviour
{
[SerializeField] float speed = 20f;
public Vector2 movement;
public float lrCMovement;
public float udCMovement;
[SerializeField] float rotationX;
[SerializeField] float rotationY;
// Start is called before the first frame update
void Start()
{
}
public void onCameraMove(InputAction.CallbackContext ctx)
{
movement = ctx.ReadValue<Vector2>() * speed;
lrCMovement = movement.x;
udCMovement = movement.y;
}
// Update is called once per frame
void Update()
{
transform.rotation = new Quaternion(transform.rotation.x + -udCMovement *
Time.fixedDeltaTime, transform.rotation.y + lrCMovement * Time.fixedDeltaTime,
transform.rotation.z, 1);
}
}
我制作了一個 object,我希望它通過游戲手柄桿根據用戶輸入進行旋轉。 但是,當桿向一側傾斜更長時間時,它不會旋轉 360 度,而是在大約 40 度處停止。 有誰知道我做錯了什么?
首先, Quaternion
並不比末尾為 1 的向量復雜很多,因此您不能只添加到 x、y 和 z。 但是你可以這樣做
transform.rotation *= Quaternion.Euler(-udCMovement *
Time.fixedDeltaTime, lrCMovement * Time.fixedDeltaTime, 0);
因為您使用Time.fixedDeltaTime
我建議您使用FixedUpate
或使用Time.deltaTime
並且不要錯過並匹配它們。
我懷疑這是萬向節鎖定的情況。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.