Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Unity平滑跟踪保持同步的摄像头_C#_Math_Camera_Unity3d_Game Physics - Fatal编程技术网

C# Unity平滑跟踪保持同步的摄像头

C# Unity平滑跟踪保持同步的摄像头,c#,math,camera,unity3d,game-physics,C#,Math,Camera,Unity3d,Game Physics,我正在做一个持续的跑步者侧滚游戏,玩家不断地从左向右移动,速度越来越快,当玩家跳跃时,他会在有限的时间内获得一些额外的速度 我的相机跟随代码如下(C#): 现在,它在低速时工作良好,当玩家跳跃时,相机会平稳跟随。 然而,随着玩家速度的提高,相机越来越落后,玩家越来越向屏幕右侧移动 我想让玩家在地面上时与屏幕右侧的距离保持不变,无论其奔跑速度如何,但当他跳跃并获得短速度提升时,相机应平稳处理,而不是向前倾斜 这怎么可能 谢谢 enter code here public float smoothS

我正在做一个持续的跑步者侧滚游戏,玩家不断地从左向右移动,速度越来越快,当玩家跳跃时,他会在有限的时间内获得一些额外的速度

我的相机跟随代码如下(C#):

现在,它在低速时工作良好,当玩家跳跃时,相机会平稳跟随。 然而,随着玩家速度的提高,相机越来越落后,玩家越来越向屏幕右侧移动


我想让玩家在地面上时与屏幕右侧的距离保持不变,无论其奔跑速度如何,但当他跳跃并获得短速度提升时,相机应平稳处理,而不是向前倾斜

这怎么可能

谢谢

enter code here
public float smoothSpeed = 0.125f;
public Vector3 offset;
private Vector3 desiredPosition;

void FixedUpdate(){
    Vector3 smoothedPosition = Vector3.Lerp(transform.position, 
                                  desiredPosition, smoothSpeed);
    transform.position = smoothedPosition;    

}

只要调整偏移矢量3,它就会工作得很好。我希望

“我想保持玩家和屏幕右侧之间的距离不变,不管他的跑步速度如何,但在他跳跃时获得短暂的速度提升时,也要保持一个平滑的摄像头。”这两个标准是相互排斥的,除非你只想在垂直轴上进行平滑的相机跟踪。我明白,我会重新措辞,我编辑了这段,我希望这更清晰。
enter code here
public float smoothSpeed = 0.125f;
public Vector3 offset;
private Vector3 desiredPosition;

void FixedUpdate(){
    Vector3 smoothedPosition = Vector3.Lerp(transform.position, 
                                  desiredPosition, smoothSpeed);
    transform.position = smoothedPosition;    

}