# 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://3798176112-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZcBSvjNQZSas5L9C0K8K%2Fuploads%2FRm5z0fsGow7RceRYQ7Hn%2Fezgif.com-gif-maker%20\(15\).gif?alt=media)

### General setup

In the *Hierarchy* of the scene you can see three core Prefabs:

`Core Scene Setup` and `Coherence Setup` are present in all scenes and described in detail on [Start Tutorial](https://docs.coherence.io/0.9/tutorial-project/network-playground) page.

`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 disconnecting/reconnecting via the interface without refreshing the scene.

### In this scene...

`Coherence Entity Character` (remember to 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 color 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 whether it is locally simulated or synced over the network.

![](https://3798176112-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZcBSvjNQZSas5L9C0K8K%2Fuploads%2FU1unt64gyadgY2PwX93y%2FPlayground_Scene2%20\(1\).png?alt=media)

### 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 how replication works for each.
