# 2. Physics

## Physics

This scene will show you how to use **coherence** to sync GameObject transforms and Physics objects across the network.

In this example, each client will have its own player character to move. Left-clicking on the map will make the entity move to that location. Right-clicking will spawn local physics based objects that all player characters can interact with. Each client will only have control over its local entity.

![](https://3643360286-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MWd0ZPEK7vE9nkE0b7G%2F-MWdj_X5MWVLYB84FeLy%2F-MWdlaGRA0E8iTQ-4SJS%2Fezgif.com-gif-maker%20\(15\).gif?alt=media\&token=598f853c-cfdf-4e07-bfe6-c4c1bd0aa947)

### General Set Up

In the *Hierarchy* of the Scene you can see three core Prefabs:&#x20;

`Core Scene Setup` and `Coherence Setup` are present in all scenes and described in detail in [Exploring the Network Playground](https://app.gitbook.com/s/-MWd0ZPEK7vE9nkE0b7G-2778409309/tutorial-project/network-playground/%7B%7B%3C%20ref%20starter_project_explore%20%3E%7D%7D).

`Coherence Entity` is the prefab that will change per Scene with different functionality. It has a standard `CharacterController`and `Rigidbody` as well as an `Agent` script which will handle movement functionality through the `Input Manager` in the `Core Scene Setup` prefab.

`Coherence Connection Events` handles overall Scene connectivity. Additionally, it removes all Entities with `coherenceSync` from the Scene to demo disconnection/reconnection via the Interface without refreshing the Scene.

### In This Scene...

`Coherence Entity Character` (always change the prefab, not the instance) is located in the *Resources* folder. The `UnityEngine.Transform` and `position` are ticked to sync. All other settings (persistence and authority) use the default settings. This entity will be session based, no authority handover and no adoption will take place, when a client leaves.

The `On Network Instantiation` event is used to change the colour of the mesh.

The `Physics Entity Spawner` is a simple script to instantiate a `Coherence Entity Physics` Prefab with a coherenceSync component that replicates the transform and position. The component also changes the material based on if it is locally simulated or synced over the network.

![](https://3643360286-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MWd0ZPEK7vE9nkE0b7G%2F-MWd0lSeuyjpQvRaoQWl%2F-MWd5LU_vVRoUkYFsulF%2FPlayground_Scene2%20\(1\).png?alt=media\&token=f022f331-176d-479a-8f74-3f21aab99434)

### Build and Try

You can build this Scene via the Build Settings. Run the local Replication Server through the *Window -> Coherence -> Settings* window and see how it works. You can try running multiple clients rather than just two and see replicating for each.&#x20;
