Which are the best settings to sync position & rotation ?

Hi,Im trying to up a cars game with photon, but I have still many troubles with that synchronizing.I had try many scripts but that's not really good synced. I'm wondering about PhotonNetwork.sendRate & PhotonNetwork.sendRateOnSerializeDo you think that leave the default settings is fine or I must change these values ?

0

Best Answers

Conclusion : All the time, positions of the players are late and something there are lagging ...

This is 'normal' behaviour due to lag / latency, but you have options to deal with them. Therefore I would recommend you taking a look at my comment here. It is basically a hint for taking a look at the PUN2 Beta package which has a new demo including something we call Lag Compensation in order to get mostly rid of such issues. There will be also a new documentation page about this topic in the next days / weeks - no ETA about this one.

Answers

increasing the sendRate doesn't automatically fixes any occurring synchronization issues. Also increasing the value too much could end in even worse results than before.

What kind of synchronization issues do you have? Are synchronized objects stuttering in at least one client's view? Are there a lot of position offsets between clients' views? Please share us some more details about this.

Conclusion : All the time, positions of the players are late and something there are lagging ...

This is 'normal' behaviour due to lag / latency, but you have options to deal with them. Therefore I would recommend you taking a look at my comment here. It is basically a hint for taking a look at the PUN2 Beta package which has a new demo including something we call Lag Compensation in order to get mostly rid of such issues. There will be also a new documentation page about this topic in the next days / weeks - no ETA about this one.

I'm looking for the script of the asteroid & the spaceship in the PUN2 package and as I can see, it works with the velocity. Currently my players are moving through transform.translate instead of rigidbody.velocity, I dont know if I can do something in this case ?

Yes, in the demo we are working with the Rigidbody component. The velocity value describes the movement of the object (direction and speed). Based on the current and the previous position of the transform component you should be able to 'create' the necessary information yourself and send this value in the OnPhotonSerializeView, too. I have not tested this behaviour, but I'm pretty sure that this will work as well.

I think there are some issues in your code. I'm starting with the OnPhotonSerializeView implementation, especially with the 'receiving' side, where you apply updates directly to the Rigidbody component. This is basically okay, but I think you don't have to do this. Instead try storing those updates in local variables and apply them later. The problem is that you are updating the ship's position at this point, which might result in stuttering movement. The better visual result in my opinion is - as said - to store the calculated position in a local variable and update it in the Update function, as seen in the Spaceship class from the PUN2 Asteroids demo.

Some words on the Update function you already have: I don't know if it is working this way (usage of destination variable) so you have to try and figure that out. What I have tried in the meantime is to store the transform.position value in a local variable ('oldPosition'), processing all input and calculating the 'movement', which is transform.position (updated) - oldPosition. The sender then uses this value as third value. On the receiving side it is more or less the same as shown in the Asteroids demo.

Some other hints to the Update function: make sure to use the PhotonView.isMine condition to avoid input from remote clients for example. Again I recommend taking a look at the implementation from the Asteroids demo, you can re-use a lot of its code in my opinion.

Edit² : After reflexion I think that the most simple way to sync player based on Pun2 script is to go through that RigidBody.velocity instead transform.Translate, I'll try to set up my code and I ll see if it's good.All the text below is about a method to convert a float value to a Vector3, it's relatively off topic, do not pay attention

I'm trying to convert my float value which represent the current speed of the gameObject to a Vector3. Then I can send this value over the network based on the SpaceShip script, I currently got this : ( I know it's a bit too long, but I allow myself to put it " in full " )

You can try this and see, if the result looks more satisfying for you. I guess you can also remove the replacement for the CheckExitScreen function if you don't need it. In your FixedUpdate function you are updating the Transform component of the object. since you are already using the Rigidbody component, you can also try updating the Rigidbody instead of the Transform component. Besides that I think this looks fine so far.

For more information you can also take a look at the new documentation page which is available now. It covers both approaches for using objects with and without Rigidbody components.

Ok thank you, ill try to resolve this issue. To be sure, Can I try this script on PUN1 ? Because I'm wondering why that spaceship & asteroid script are only on PUN2 ?Edit : Lerp solved my issue, there is a llittle bit offset on each player position but it's normal from that lerp. Thank you !

Following your help and the resolution of my sync position issue, this has generated an another one ^^. I'm not creating an another thread because that issue is related to the previous. I am not in a hurry and ill try to explain this issue, I hope that someone could help me

When players are moving they generate a gameobject behind them every 0.3 sec. In my Update() function there is the followinf code :

if (0.0 >= nextWall) // if it's time to generate the gameObject
{
nextWall = 0.3f; //set countdown for the next gameObject
GameObject collider;
collider = Instantiate(Enemy, Rb.position + Rb.transform.forward * distance, Rb.rotation);//instantiate the gameObject just behind the rigidbody component on the local player
Photonview.RPC("SpawnCollider", PhotonTargets.Others);// the local player generate his gameObject over the network for the others players
}
if (nextWall > 0.0f) // if the generation of the gameObject is reloading
{
nextWall -= Time.deltaTime; // we wait a delay and the next gameObject can be generated
}
[PunRPC]
private void SpawnCollider()
{
GameObject collider;
collider = Instantiate(Enemy, Rb.position + Rb.transform.forward * distance, Rb.rotation);
}

Well, the issue is like the previous one, the gameObject is created over the network but it's only synced on the local side. I also tried alternative but I just lost about ten hours ^^. ( for example try to add compensation from lag : nexWall = 0.3f - netLag, I tried througt allViaServer method ... )I just made a picture to illustrate the situation : https://www.noelshack.com/2018-06-4-1518044851-bmj.jpg

Have you already tried sending the position of the new game object with the RPC call itself? This way you would make sure that the object has the same position on all clients. For example: Photonview.RPC("SpawnCollider", PhotonTargets.Others, position);

Just for telling that my world scale was too bit, the the sync was right but I remade a new space with a bigger scale like * 70 - 100 and now I can use that Vector3.MoveTowards, it's not jerky anymore and player moves are more accurate.