C# 为什么我的相机动作如此紧张?

C# 为什么我的相机动作如此紧张?,c#,mobile,optimization,unity3d,game-development,C#,Mobile,Optimization,Unity3d,Game Development,几天来,我一直在努力为我的比赛平滑我的相机运动,但我无法让它达到一个合理的平滑水平。我可以对这段代码做一些修改来提高平滑度吗?我也尝试过moveTowards()函数,但没有效果 /**************************** CAMERA MOVEMENT *********************************/ void FixedUpdate () { //Do we need to spawn new platforms yet?

几天来,我一直在努力为我的比赛平滑我的相机运动,但我无法让它达到一个合理的平滑水平。我可以对这段代码做一些修改来提高平滑度吗?我也尝试过moveTowards()函数,但没有效果

/**************************** CAMERA MOVEMENT *********************************/

void FixedUpdate () {
            //Do we need to spawn new platforms yet? 
            Vector2 playerHeight = playerTransform.position;
            if (playerHeight.y > nextPlatformCheck) {
                    PlatformMaintenaince (); //Spawn new platforms
            }

            //Update camera position if the player has climbed 
            Vector2 currentCameraHeight = transform.position;

            if (playerTransform.position.y > currentCameraHeight.y) 
            {
            transform.position = Vector2.Lerp(new Vector2(transform.position.x,0.0f), new Vector2(0.0f, playerHeight.y), smooth * Time.deltaTime);
            } 
            else {
                    // If player is too low, gameover.
                    if ((playerHeight.y) < (currentCameraHeight.y - 5.5)) {
                            GameOver();
                    }
            }
    }
/*************************摄像机运动*********************************/
无效固定更新(){
//我们还需要开发新的平台吗?
Vector2 playerHeight=播放器转换位置;
如果(playerHeight.y>nextPlatformCheck){
PlatformMaintenance();//生成新平台
}
//如果播放机已爬升,则更新摄像机位置
Vector2 CurrentCamerahHeight=transform.position;
如果(播放转换位置y>currentCameraHeight.y)
{
transform.position=Vector2.Lerp(新矢量2(transform.position.x,0.0f),新矢量2(0.0f,playerHeight.y),平滑*时间增量);
} 
否则{
//如果玩家太低,游戏结束。
如果((playerHeight.y)<(currentCamerahheight.y-5.5)){
GameOver();
}
}
}

使用更新功能而不是固定更新。FixeUpdate仅在一定数量的od帧后调用

所有相机移动计算都应该在
LateUpdate()
中执行,让
Update()
获取球员位置,然后让相机在更新计算后使用该位置。

尝试Time.fixedDeltaTime。在
Update
中更新相机,而不是在
FixedUpdate
中更新相机。