Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

p2.js Multiplayer Game issue #357

Open
ghost opened this issue Apr 23, 2020 · 3 comments
Open

p2.js Multiplayer Game issue #357

ghost opened this issue Apr 23, 2020 · 3 comments

Comments

@ghost
Copy link

ghost commented Apr 23, 2020

I was trying to make a game with socket.io and p2.js. I was thinking of sending the world instance to the client from the server, then having the client render it. I wasn't able to send the instance of world to the client because the object has a circular structure. Any idea of how to tackle this issue?

@ghost
Copy link
Author

ghost commented Apr 24, 2020

Nevermind, I made a custom flattening script. Now my server can't do world.step(1/30) because it returns a maximum call stack reached error.

@Fxlr8
Copy link

Fxlr8 commented May 15, 2020

Sending the whole world state every tick is extremely inefficient and practically useless. Try to send as little information as possible. For example, only send positions of the objects that move. Then apply this updates to the client's state. Game networking is a complex task

@XWILKINX
Copy link

I use Socket.IO and P2.js for my real-time multiplayer game Deadswitch 3.

It's not possible to emit the world instance to a client (hence the maximum call stack error) due to circular dependencies.

Instead, simply send any position/velocity/data changes that occurred. I recommend sending this at a interval, not every frame. Personally I send data updates 5 times a second, and let the client handle interpolation.

Let me know if you have any other questions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants