Unity3D Choppy Camera Motion

房东的猫 提交于 2019-12-04 22:24:32

@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.

Try using the Lerp function instead directly moving the transform.position.

It would be something like transform.position = Vector3.Lerp(startPosition, endPosition, time);

It should be smooth using this. You have more information and examples at Vector3.Lerp Unity3D

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!