簡體   English   中英

為什么物體旋轉太慢? 以及如何使對象在不旋轉時面向原始方向?

[英]Why the object is spinning too slow ? And how can I make that the object will face forward original direction when not rotating?

private void Update()
    {
        if(toRotate == true)
        {
            transform.Rotate(Vector3.forward, Time.deltaTime * 10);
        }
    }

即使將速度更改為 100,它也非常慢。 我希望當不旋轉添加其他轉換時,默認情況下變換將面向前方。

這適用於快速旋轉:

transform.Rotate(0,0,100);

這對這兩個問題都有效:

private void Update()
    {
        if(Whilefun.FPEKit.FPEInteractionManagerScript.naviRotate == true)
        {
            transform.Rotate(0,0,100);
        }
        else
        {
            transform.eulerAngles = new Vector3(0, 0, 0);
        }
    }

這是因為Time.deltatime ,導致Time.deltatime返回兩個連續幀之間的差異,如果您的幀率很高,這是一個非常小的數字。 就我而言,FPS 為 85,我的 deltatime 約為 0.0166682。

並且我想讓這個數字大到 16.6682 然后我必須將它乘以1000 ,如果我將它乘以100我只會得到1.66682 ,這是慢速旋轉,在這個速度下旋轉將需要2.54 秒來旋轉它360 度。

對於旋轉,您只需說transform.localrotation = Quaternion.identity即可將對象的旋轉設置為零。

在您的第一個示例中,您以錯誤的方式使用了 transform.rotate()。 第一個參數確實應該是一個 Vector3(),表示歐拉角,但第二個參數應該是旋轉的參考坐標系,Space.Self 或 Space.World。

如果我正確理解您要實現的目標,則應使用如下函數:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Stack_rotate : MonoBehaviour

{
     float rotationAngleOverZAxisPerFrame = 1200f;

     void Update()
     {
         transform.Rotate(new Vector3(0, 0, rotationAngleOverZAxisPerFrame * Time.deltaTime), Space.Self);
     }
}

旋轉對象可能非常令人沮喪,因為有多種方法可以統一指定對象旋轉。

暫無
暫無

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

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