繁体   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