Photon Unity NetworkingのPhotonTransformViewで微妙にずれる

  • 投稿日:
  • by
  • カテゴリ:

位置同期をPhotonTransformViewで行う際、
補間処理(Interpolate Option)は「Estimated Speed」を使うのが良さそうなのだが
移動停止した時の座標が完全に同期せずわずかにずれたままになる現象がある。

これを解消するには、PhotonTransformViewPositionControl.csの91〜94行目あたりを下記のようすると良さそう。

float estimatedSpeed = (Vector3.Distance(m_NetworkPosition, GetOldestStoredNetworkPosition()) / m_OldNetworkPositions.Count) * PhotonNetwork.sendRateOnSerialize;
if (estimatedSpeed < 1f)
{
currentPosition = targetPosition;
}
else
{
// move towards the targetPosition (including estimates, if that's active) with the speed calculated from the last updates.
currentPosition = Vector3.MoveTowards(currentPosition, targetPosition, Time.deltaTime * estimatedSpeed);
}

要は、推定速度がほぼ0になってしまうと最後まで移動してくれないので
速度 1f未満なら強制的に目標値ぴったりに移動させている。

Photonを使い始めるにあたっては下記の記事がすごく丁寧で分かりやすい。
【Unity】僕もPhotonを使いたい #01〜#14