Skip to content

Commit

Permalink
优化网络同步 平滑小车移动
Browse files Browse the repository at this point in the history
  • Loading branch information
TastSong committed Apr 15, 2024
1 parent bf35865 commit 10ac268
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion CrazyCarClient/Assets/Scripts/Game/MPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ public class MPlayer : MonoBehaviour, IController {

// 消除移动时的顿挫感
private Coroutine moveNetCarCor = null;
private float smoothSpeed = 1;
private float smoothSpeed = 4f;
private Vector3 currentVelocity = Vector3.zero;

private void Start() {
pathCreator = this.GetModel<IMapControllerModel>().PathCreator;
Expand Down Expand Up @@ -138,6 +139,7 @@ private IEnumerator MoveNetCar(Vector3 pos, Vector3 speed) {
yield return new WaitForSecondsRealtime(Time.deltaTime);
transform.position = Vector3.Lerp(transform.position, pos, Time.deltaTime * smoothSpeed);
rig.velocity = Vector3.Lerp(rig.velocity, speed, Time.deltaTime * smoothSpeed);
rig.velocity = Vector3.SmoothDamp(rig.velocity, speed, ref currentVelocity, Time.deltaTime * smoothSpeed);
time -= Time.deltaTime;
}
}
Expand Down

0 comments on commit 10ac268

Please # to comment.