The Photon Forum
is Closed Permanently.

After many dedicated years of service, we have made the decision to retire our Forum and switch to read-only: we´ve saved the best to last! Your search result can be found below. Plus, we offer support via these channels:

Try Our
Documentation

Please check if you can find an answer in our extensive documentation on PUN.

Join Us
on Discord

Meet and talk to our staff and the entire Photon-Community via Discord.

Read More on
Stack Overflow

Find more information on Stack Overflow (for Circle members only).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

Proper way to sync physics and collisions

Recursion
2018-07-16 13:47:23

I'm using PUN for my 2D game, which uses physics as the main method of moving enemies from one place to the player(to kill him. Very morbid, I know). Currently I'm using a Rigidbody2DView coupled with a TransformView syncing the position with the interpolate option disabled, which works fine, until the enemy gets hit with a player projectile, at which point it goes all weird and starts flying around on the client, eventually stabalizing itself after a second or 2, but there's a noticeable problem.

I'm guessing this is because the projectile is colliding with the enemy on the master client and the client, but then the data gets synced from the master client to the client, and it goes all weird.

So is there A) any way to sync collisions, or B ) a better system for syncing physics?

Many thanks in advance.

Comments

Recursion
2018-07-16 13:48:50

EDITED: original post edited to replace B) with B )

Sorry about the random B), I meant to put B )

[Deleted User]
2018-07-17 09:08:38

Hi @Recursion,

I'm guessing this is because the projectile is colliding with the enemy on the master client and the client, but then the data gets synced from the master client to the client, and it goes all weird.

You are probably right: the client detects a collision which affects the object's velocity and furthermore tries to update the position. Since the Owner (MasterClient in this case) didn't notice the collision, he applies another movement to that object. This results in the behaviour you described above.

You can try to add Lag Compensation and see if this is already enough to solve the problem. Lag Compensation is an approach to get a better synchronization between different clients. If the problem persists afterwards, you should adjust the game logic in terms of collision detection. Collisions affecting a certain object should only be handled by its certain owner in order to avoid the described problems.

Recursion
2018-07-19 13:42:02

Thanks so much for your suggestions. Lag compensation was a bit iffy for me, so instead I made the colliders on the projectiles on all the clients triggers(The master client will always own the enemies), and used OnTriggerEnter2D instead of OnCollisionEnter2D.

Back to top