# Collisions on client, versus server occur at different locations

**URL:** <https://phaser.discourse.group/t/collisions-on-client-versus-server-occur-at-different-locations/8564>\
**Category:** Phaser 3\
**Created:** [January 5, 2021, 9:06am UTC](https://phaser.discourse.group/t/collisions-on-client-versus-server-occur-at-different-locations/8564 "2021-01-05T09:06:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![TomYeoman](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/tomyeoman/32/4572_2.png) [@TomYeoman](https://phaser.discourse.group/u/TomYeoman)\
**Post date:** [January 5, 2021, 9:06am UTC](https://phaser.discourse.group/t/collisions-on-client-versus-server-occur-at-different-locations/8564/1 "2021-01-05T09:06:28Z")

</div>

I’m creating a game, where I’m running phaser on both the client, and server.

Both are using Arcade physics, with an identical config. They both use a tiled map, and the same code to create an entity.

The problem i’m having, is probably easiest to explain via a GIF. In the example there’s 2 players - one represents the client (black outline), and the server (pink outline)

 ![collision-client-versus-server](https://global.discourse-cdn.com/free1/uploads/phaser1/original/2X/5/5e47d989c2bece6ac95d6cea1451b106674983dd.gif)

When I get to the building, you can see my client sprite, is stopped about 20px before my server one.

So to break it down -

- Both server and client, start at **Y=1216px**
- Player moves up smoothly on client, up until it hits client side collision @ **Y=1128px**
- The server however receives my input (up), and carries on past the clients detection, with the collision not taking affect until **Y=1112px**

Now I have a client, which is out of sync with my server, which causes problems once I add client side reconciliation back in (the client would try to jump to a position, which isn’t actually allowed)

Here’s my code for reference -

_Phaser setup_

- **Server** - [https://github.com/TomYeoman/2d-shooter-2020/blob/9d386ab854a40a8cc2cb8042bd259fd0bc8f6abc/server/src/game/config.ts#L10](https://github.com/TomYeoman/2d-shooter-2020/blob/9d386ab854a40a8cc2cb8042bd259fd0bc8f6abc/server/src/game/config.ts#L10)
- **Client** - [https://github.com/TomYeoman/2d-shooter-2020/blob/9d386ab854a40a8cc2cb8042bd259fd0bc8f6abc/frontend/src/App.tsx#L350](https://github.com/TomYeoman/2d-shooter-2020/blob/9d386ab854a40a8cc2cb8042bd259fd0bc8f6abc/frontend/src/App.tsx#L350)

_Creating tile-map_

- **Server** - [https://github.com/TomYeoman/2d-shooter-2020/blob/9d386ab854a40a8cc2cb8042bd259fd0bc8f6abc/server/src/game/scene.ts#L71](https://github.com/TomYeoman/2d-shooter-2020/blob/9d386ab854a40a8cc2cb8042bd259fd0bc8f6abc/server/src/game/scene.ts#L71)
- **Client** - [https://github.com/TomYeoman/2d-shooter-2020/blob/9d386ab854a40a8cc2cb8042bd259fd0bc8f6abc/frontend/src/App.tsx#L100](https://github.com/TomYeoman/2d-shooter-2020/blob/9d386ab854a40a8cc2cb8042bd259fd0bc8f6abc/frontend/src/App.tsx#L100)

Entity setup code (server watches ALL entities for collisions, client only adds collision to the actual player driving that client )

- **Server** - [https://github.com/TomYeoman/2d-shooter-2020/blob/57630701eee04a8258973b9b5f0ea966128eab2b/server/src/game/entity/entity.ts#L34](https://github.com/TomYeoman/2d-shooter-2020/blob/57630701eee04a8258973b9b5f0ea966128eab2b/server/src/game/entity/entity.ts#L34)
- **Client** - [https://github.com/TomYeoman/2d-shooter-2020/blob/57630701eee04a8258973b9b5f0ea966128eab2b/frontend/src/game-objects/entity/entity.ts#L32](https://github.com/TomYeoman/2d-shooter-2020/blob/57630701eee04a8258973b9b5f0ea966128eab2b/frontend/src/game-objects/entity/entity.ts#L32)

both have the collision added to the same tile-map layer

Does anyone have any ideas this might be?

---

<div class="post-metadata">

**Author:** ![yannick](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/yannick/32/732_2.png) [@yannick](https://phaser.discourse.group/u/yannick)\
**Post date:** [January 5, 2021, 3:46pm UTC](https://phaser.discourse.group/t/collisions-on-client-versus-server-occur-at-different-locations/8564/2 "2021-01-05T15:46:17Z")

</div>

You can use electron to debug the physics on your server: [Phaser 3 - Real-Time Multiplayer Game with Physics #2](https://phaser.discourse.group/t/phaser-3-real-time-multiplayer-game-with-physics-2/6076)

_You can code your server side game in an isomorphic way to be able to run it on electron (debug) or node.js (production)._
