- Home /
Photon Network Movement Delay
Hello! First... sorry for my english, not so good!
I'm having troubles testing with player movements on Photon, imagine I open 2 windows:
On play, I instantiate a "Player", with PhotonView and a Network script with this:
private Vector3 correctPlayerPos;
private Quaternion correctPlayerRot;
void Update()
{
if (!photonView.isMine)
{
transform.position = Vector3.Lerp(transform.position, this.correctPlayerPos, Time.deltaTime * 7);
transform.rotation = Quaternion.Lerp(transform.rotation, this.correctPlayerRot, Time.deltaTime * 10);
}
}
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.isWriting)
{
stream.SendNext(transform.position);
stream.SendNext(transform.rotation);
}
else
{
this.correctPlayerPos = (Vector3)stream.ReceiveNext();
this.correctPlayerRot = (Quaternion)stream.ReceiveNext();
}
}
This test is like a 3rd person shooter, when I move one player I can see it on the other windows moving correctly, smoothly, BUT it have a small delay on movement... just some miliseconds, but enough to malfunction...
While player 1 is running, if you take a look at 2nd window it is moving some "steps" behind. When I shoot with player 1 to an static objective, on window 1 the bullet collides with the objective, on window 2 the bullet doesn't collide, it's some "steps" behind...
What can I do? I can't find a solution, I tried to "predict" the real position adding the velocity variable to the "correctPlayerPos" unsuccessfully...
Thank you
Answer by rbisso · Jul 23, 2015 at 11:27 PM
Did you try using the PhotonTransformView to synchronize the positions?
I would recommend doing this tutorial and analyzing their steps thoroughly before heading off on your own: https://doc.photonengine.com/zh-cn/pun/current/tutorials/rpg-movement
Also, as a heads-up, you're going to want your bullets to be instantaneous and deterministic in the way that they travel/hit to account for lag. If you have a very unforgiving system, it's going to fail often.
Thank you, I will test this.
Which is the best way to do this?, imagine for example:
An online game where each player is moving a tank in 3rd view, the tank can rotate the gun and shoot a bullet in the direction where the gun is pointing.
If I start to moving the tank to the right and shot up, I can see how the bullet strikes on the enemy tank, but the other player on his screen look like the bullet goes slight to the left, on his screen I'm still not in front of him, because of the delay I am slightly to the left and the ball does not impact.
There are many games in which this works well, for example in league of legends where the movement is very fast, everyone sees enemies in the correct position. I need to understand how to make the positions of the players 100% accurate.
Or in Counter Strike, the position of the players must be 100% perfect or the game would be unplayable.
This games look smooth and the position is perfect... any idea how can I do it?
I've tested PhotonTransformView, the unique option working "almost" correctly is Extrapolate: Estimated speed and turn, but the visual movement is really bad...
There must be another way to do this, or $$anonymous$$$$anonymous$$ORPG games can't exist, there can't be this difference in the position of the players ...
Your answer
Follow this Question
Related Questions
MultiPorposeCameraRig makes the camera float 0 Answers
player not moving over the bridge 1 Answer
photon player movement 1 Answer
Player rotation restricted even though I don't want it to be 0 Answers
Photon Player Controls Other Player 0 Answers