2
\$\begingroup\$

I'm making a multiplayer game in HTML5 Canvas and Node using Express and Socket.io. It's a platformer style game and so far the players are able to see each other and move around on the screen. It works pretty well, but most of my game logic is client side which I believe might become a problem. The movement of other players at the moment isn't very smooth at all. So far, the only thing the server does is recieve the position and velocity of the players, and then broadcast it out to all the other players so they can see each other. I was wondering if there was a smarter way to go about this? Everything like collision detection, movement, key inputs etc is all used client side. Should this be server side instead? I could imagine that if I calculated things like collision detection and movement server sided, then there would be no way for the player to do things like edit their position via the browser console and change their size etc.

I hope it's not too complicated. I haven't written much code yet since I would like to make sure I do it the correct way from the start without having to change and rewrite a lot of code. Let me know if you'd like to see my code.

\$\endgroup\$
2
  • \$\begingroup\$ While there is no definitive right or wrong, it is common practice that you do as little logic as possible client side and use it more to render the results the server provide. \$\endgroup\$
    – Mikael
    Commented Dec 3, 2015 at 13:50
  • \$\begingroup\$ @boredatwork So calculating all things like collision, map, other player positions etc. would be best to do server side? \$\endgroup\$ Commented Dec 4, 2015 at 6:22

1 Answer 1

1
\$\begingroup\$

Talking about online games - all logic/collision/actions should be manager on server. (because user is a cheater by default)

I understand that maybe one single unit jump with 50-100ms ping will looks weird (as websockets guarantee package delivery, but also a bit slower because works under http).

So let's imagine jump logic:

  • user press space (or up) to jump
  • unit immediately jump on client (just if your want super-fast feedback)
  • also at the same time you sent "jump" message to server
  • server-side unit also jump and broadcast it for all observers (including current user)
  • each client overwrite unit info with server data.

so there is two ways:

  • move all physic/logic to server
  • move all physic/logic to server AND mirror it on client to get quick feedback

moment isn't very smooth at all

For example my server tick is about 150 ms. Sometimes up to 200ms. So movements can't be smooth at all. But I solved it in render. I've made some analog of .animate() from old jquery (1.2 or something) and all changes becomes smooth.

Maybe it's a bit more complex for platformer, as it's not just a vector & speed, so here you should mirror some logic on server as on client.

But keep in mind - client vs. server - server always right, even when both doing the same.

I hope it will help :3

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .