2D Jump And Run Demo

This scene demonstrates how Photon can be used to synchronize 2D objects and how a combination of position and physics updates can result in smooth movement of synchronized objects. The main character has two components applied, PhotonTransformView and PhotonRigidbody2DView. If you want to learn all the details of the PhotonTransformView, you should check out the RPG Movement Demo.

Screenshot of 2D Jump And Run Demo
Animated Demo Characters

The PhotonRigidbody2DView’s simple inspector gives you the options to synchronize the objects velocity and/or its angular velocity. Since the character is moved by those forces, the resulting movements on remote clients is as smooth at it is on the local client.

PhotonRigidbody2DView in Jump And Run Demo
PhotonRigidbody2DView in Jump And Run Demo

Unity’s physics simulation is not deterministic – meaning the same input can have slightly different outputs. This is why you should never rely on just synchronizing the physics data because the small differences will add up over time and the simulations on the different connected clients will run out of sync. We are using the PhotonRigidbody2DView in combination with the PhotonTransformView to combat this. The PhotonTransformView will send the actual, correct positions at regular intervals and the velocities of the PhotonRigidbody2DView are used to have smooth movement in between position updates.

By synchronizing the velocity, you also make sure that correct impact forces are applied to level objects if you character crashes into them. This is demonstrated by the physics cubes that are spawned in the scene.

Additional Notes

You might notice that some collision boxes covers multiple red tiles (the pieces you can stand on). The reason is that if every red box has a seperate collider, the characters get "stuck" on the edges between boxes and movement becomes yerky.

Less colliders also provide better performance (not relevant in this demo).

 To Document Top