Ana*_*bal 8 unity-game-engine ios jitter unity5
我正在为Unity iOS开发一个非常简单的垂直滚动游戏.我的游戏正在经历不一致的抖动.我已经广泛搜索了网络,寻找没有任何运气的解决方案.我正在使用Unity版本5.3.4 f1.
游戏
Update()(Time.deltaTime正在成倍增加).LateUpdate()(使用Vector3.Lerp()后跟).问题
我们尝试了什么
Update(),LateUpdate(),FixedUpdate(),Time.deltaTime Time.smoothDeltaTime线性插值,减少现场的几个立方体和删除所有对撞机和触发器.我完全没有想法.任何帮助或指针将受到高度赞赏.
提前致谢.
这可能是由很多不同的原因引起的,在没有看到任何代码的情况下,我只能提出一些想到的建议:
\n\n1.浮点精度误差
\n\n这将表明存在浮点精度错误。不要让角色掉落,而是将角色周围的对象从屏幕视图下方移动到屏幕视图上方,以便一切都发生在原点附近。
\n\n2. 经常实例化或其他滞后峰值
\n\nfor//foreach循环吗while?实例化会导致滞后峰值并产生垃圾,从而导致垃圾收集器更频繁地运行。由于帧速率是固定的,因此当发生缓慢操作时,您会看到一些抖动。
\n\n当玩家走一段距离时,您不应该实例化和销毁对象,而应该Instantiate在场景加载后创建一个游戏对象池,使用 使它们处于非活动状态gameObject.SetActive(false),并将它们存储在列表、数组等中,当您需要Instatiate新对象时,只需简单地从池中取出一个,并Transform.position在gameObject.SetActive(true)需要时进行更换。
3.垃圾收集器经常运行
\n\n这个不太可能成为问题,但仍然提到它。采取这个示例代码:
\n\nvoid Update()\n{\n Vector3 someVector = new Vector3(0,0,0);\n float distance = someVector.magnitude;\n if (distance > 5.0f)\n Vector3 someNewVector = someVector + transform.position;\n else\n Vector3 someNewVector = Vector3.zero;\n}\nRun Code Online (Sandbox Code Playgroud)\n\n每次Update运行时,它都会创建新变量并为它们分配内存。下次更新runs, it creates new variables, and allocates more memory. Eventually, the memory usage sets off the garbage collector, which goes around and frees up the memory used by all the previous更新`功能。相反,您应该在开始时分配内存,然后重用变量。
void Start()\n{\n Vector3 someVector = new Vector3(0,0,0);\n Vector3 someNewVector = new Vector3(0,0,0);\n float distance = 0f;\n}\nvoid Update()\n{\n someVector = Vector3.zero;\n float distance = someVector.magnitude;\n if (distance > 5.0f)\n Vector3 someVector += transform.position;\n else\n Vector3 someVector = Vector3.zero;\n}\nRun Code Online (Sandbox Code Playgroud)\n\n要诊断此问题,您需要附加配置文件调试器并观察抖动是否与垃圾收集器一致。
\n\n希望这里的内容对您有所帮助。查找抖动源的最佳选择是使用分析器。以下是 iOS 的说明:
\n\n\n\n\n将您的 iOS 设备连接到 WiFi 网络(探查器使用本地/临时 WiFi 网络将分析数据从设备发送到 Unity 编辑器)。在 Unity\xe2\x80\x99s build\n 设置对话框中选中 \xe2\x80\x9cAutoconnect Profiler\xe2\x80\x9d 复选框。通过电缆将您的设备连接到 Mac,选中 Unity\xe2\x80\x99s 构建设置对话框中的\n \xe2\x80\x9cDevelopment Build\xe2\x80\x9d 复选框,然后点击\n \xe2\x80\x9cBuild &在 Unity 编辑器中运行\xe2\x80\x9d。当应用程序在设备上启动时,在 Unity 编辑器中打开探查器窗口(窗口 -> 探查器)。
\n
更多信息:分析器窗口
\n