Unity3D Choppy相机运动 [英] Unity3D Choppy Camera Motion

查看:240
本文介绍了Unity3D Choppy相机运动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了许多不同的方法,但从来没有成功完成一个完美平滑的相机运动。
即使在一个非常简单的场景中,相机跟踪也不够好。运动有尖峰。峰值不会周期性地发生,而是随机发生。如果我不知道一些游戏(例如Manuganu)在团结,并有一个完美的相机跟随,我会认为这是不可能的。



我到目前为止所做的:
- 更改LateUpdate / FixedUpdate中的相机位置。
- 我的目标插值/外推。
- 根据Deltatime移动摄像头。
- 增加物理步骤。
- 设置targetframerate = 60。
- 所有质量设置,Vsync等都有。
- 许多变体和其他东西...



最好的情况是,在移动和编辑器中发生随机呃逆。
Unity的示例脚本也不能完美运行。
由于这个打嗝问题,我不能继续开发sidescroll的赛车游戏。



问题是:有没有任何方式我没有提到,是有在互联网上的任何例子?
我做了我能做的一切。

  transform.position = new Vector3(target.x,target.y, -10); 

这是我在LateUpdate中更新相机位置的方式。



PS:没有FPS丢弃问题。

解决方案

@Kashbel有一半。您使用的是固定的移动值,但不能保证每个帧都需要相同的实际时间。您需要确保每秒的单位数是常数,这意味着您需要使用时间来控制更新的速度。



典型的方式句柄这是使用 Time.DeltaTime ,它将总是一个微小的分数表示帧的真实世界长度,以秒为单位。例如,在文档中:

 使用UnityEngine; 
using System.Collections;

public class ExampleClass:MonoBehaviour {
void Update(){
float translation = Time.deltaTime * 10;
transform.Translate(0,0,translation);
}
}

这里的脚本会移动它的游戏对象10单位每秒,无论帧率如何。没有 Time.deltaTime ,它可能在一帧中以1/60秒的速度移动10个单位,而在特别慢的帧上以1/15秒的速度移动10个单位。 / p>

I tried many different methods but never succeed to make a perfectly smooth camera movement. Even in a very simple scene, camera follow is not good enough. There are spikes in motion. Spikes do not occur periodically but randomly. If I didn't know some games(e.g. Manuganu) made in unity and has a perfect camera follow, I would think it is impossible.

What I have tried so far: -Change camera position in LateUpdate/FixedUpdate. -Made my target interpolate/extrapolate. -Moved camera depending on Deltatime. -Increased physics steps. -Set the targetframerate = 60. -Played with all Quality settings, Vsync etc. -Many variations and other things...

The best scenario is, random hiccups...happening in both mobile and editor. Unity's example scripts doesn't work perfectly smooth either. I can't continue developing sidescroll runner game because of this hiccup problem.

The question is: is there any way I didn't mention, is there any example on the Internet? I did everything I can do.

transform.position = new Vector3(target.x, target.y, -10);

This is how I update camera position in LateUpdate.

PS: There is no FPS drop issue.

解决方案

@Kashbel has half of it. You're using a fixed movement value but there is no guarantee that every frame takes the same amount of real world time. You need to make sure that the units-per-second is constant, which means you need to use the time to control the speed of the update.

The typical way to handle this is to use Time.DeltaTime, which will always be a tiny fraction representing the real world length of the frame in seconds. For example, as in the docs:

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    void Update() {
        float translation = Time.deltaTime * 10;
        transform.Translate(0, 0, translation);
    }
}

here the script will move it's gameObject 10 units per second, regardless of framerate. Without the Time.deltaTime it might move 10 units in 1/60th of a second on one frame but 10 units in 1/15th of a second on a particularly slow frame.

这篇关于Unity3D Choppy相机运动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆