簡體   English   中英

圍繞Vector3.up和Vector3.left旋轉時,請勿旋轉z軸

[英]Don't rotate z-axis while rotating around Vector3.up and Vector3.left

我有一個要在Vector3.upVector3.leftrotate Vector3.left ,以便玩家可以使用Shuttle向上/向下和向左/向右查找。

這是我使用的代碼:

// Rotate the ship
transform.Rotate(Vector3.up, distX * rotateSpeed * Time.deltaTime, Space.Self);
transform.Rotate(Vector3.left, distY * rotateSpeed * Time.deltaTime, Space.Self);

其中distX是旋轉強度的值,基於Mouse X -Axis, rotateSpeed只是旋轉速度的值。

但是,如果我使用此腳本旋轉我的船,那么它也會通過z軸旋轉。

而且我不知道為什么要這么做。 這是我的代碼中(到目前為止)僅有的幾行與Shuttle的旋轉有關的事情。

我試過沒是更換Vector3.uptransform.upVector3.left通過transform.right (也改變distY-distY在第二種情況下),但也不能工作。

您可以將z的Euler值指定為0,這樣可以限制z軸的旋轉:

    distX = Input.GetAxis("Vertical") * rotateSpeed * Time.deltaTime;
    distY = Input.GetAxis("Horizontal") * rotateSpeed * Time.deltaTime;       
    transform.rotation = Quaternion.Euler(distX, distY, 0f);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM