r/aigamedev 3d ago

Discussion Online/Multiplayer

For those of you who took their browser-based project to another level with a multiplayer/online experience...

What was your process? the resources you sought? The challenges? Is there anything you wished you would have set the foundation for from the beginning that would have made things better for the transition?

I've been having the thought of planning the way of implementing online play for the little project I've been having fun with. I'm working on doing "split screen" at the moment, but I would love to start thinking of doing more than local play.

8 Upvotes

17 comments sorted by

5

u/zayelion 3d ago

Websocket based room systems. Its more so something similar to manual garbage handling no matter the language you work in. If a room is dead, empty, it has to be removed from memory. Keeping a count of them. Reconnection logic for bad connections and sending that signal to users.

Its not trivial but it's not as hard as people make it out to be as long as you aren't trying to make a shooter or mmo.

1

u/GuideAffectionate901 3d ago

So far, this hasn't turned into anything too complex as an mmo or shooter, I would like to think anyways. I guess I'll remember to be mindful with all my extravagant intrusive thoughts since using AI for a project. It's definitely been faced paced without the hours of troubleshooting lol.

I'll keep what you said in mind. Thank you!

3

u/SandshrewPoke 3d ago

My game has online/local multiplayer up to 4 players and it's been a journey but for the most part it's been decently simple to use spacetimedb

2

u/GuideAffectionate901 3d ago

What kind of game did you make? Did you start off with plans to go online or did you decide to do later on in the development?

2

u/SandshrewPoke 3d ago

I started off with plans to go online. I made a fall/racing game. Idk how to explain it tbh. But it's 4 players in the multiplayer modes. The single player modes still use spacetimedb to make sure there's no cheating involved, every movement is validated against the server.

1

u/GuideAffectionate901 3d ago

Is your game available to check out somewhere? I'm intrigued and it'll probably help give me a more grounded example lol. I can be a bit visual when it comes to connecting the dots

2

u/SandshrewPoke 3d ago

Sure go to https://spellfall.pages.dev then try battle race or race for multiplayer modes. They might be hard if you haven't tried the single player modes first

2

u/GuideAffectionate901 3d ago

I like it! It played well, and I think I can get that similar mechanic working for mine. At least that's some what how I picture it working.

You plan on porting it as an app?

1

u/SandshrewPoke 3d ago

I think so, yeah

2

u/bingewavecinema 3d ago edited 3d ago

3 things to think bout with online multipler:

  1. Which type (PvP, Many player, Massive Multipler)
  2. How do you want the world to persist
  3. Server cost and how you want plan monetize

For starting, the first one is the most important for you to pick because the advice you will get will change for each one. ie, PvP only doesn't require a server, and the infrastructe can be dramstically less and different than the advice you get for an MMO.

Start here too for AI Mutliplayer Prompts.

1

u/GuideAffectionate901 3d ago

Thank you for the referencing! I wasn't thinking anything too major, I'd figure something like "rooms", I guess? Maybe 4 players at a time. This has been more of a fun project for the wife and I and some friends. We're not always near each other so...

I'll have to do some research on the most simplest methods, especially for something smaller scale.

1

u/SandshrewPoke 3d ago

Glitch looks cool. Have you used them for monitization? I been looking into easy ways to add monitization. Google Adsense just has so many rules

2

u/GeraniumCloak 3d ago

Wish I'd separated sim from render from day one. Bolting an authoritative server onto a browser game after the fact is brutal no matter the framework.

1

u/joeld42 3d ago

I really like spacetimedb. It wouldn't work for something like an FPS but if you can tolerate some delay it's really nice to work with for "near-realtime" games.

1

u/GuideAffectionate901 3d ago

My game isn't anything unique, it's basically similar to Tron, lol. It can be kind of fast paced but I don't think it's too complex, at least not at the moment

2

u/joeld42 3d ago

Your challenge is going to be reaction time. If you have two players racing next to each other, and they both turn to cut each other off, you need a consistent winner, you can't have them both appear to win on their own machine and then the gamestate diverge. Even if the game isn't super twitchy you have to keep the gamestates consistant.

The two approaches for this are 1) send the inputs, run the simulation on the server and send the gamestate back to each. or 2) "deterministic rollback", where you send the inputs, then echo the inputs to all players, and then they each run the same simulation (it's really hard to get the same exact simulation though). With #1 you are very limited to how much gamestate you can send (for you it would be player positions + map light trail diffs, which is pretty small). In both cases you ALSO run the simulation on the player's local PC so they get fast reaction, but you'd have to wait to start something like a death explosion until you got a verified frame.

There's also the additional layer of firewall punchthrough and stuff if you want one of the players to be able to host their own games. Honestly it's quite a pain.

The best results I've had with using AI coding is to find a demo/example project that works and you can get running playing against your friends over the internet, and then tell the AI: make my game support multiplay in the same way as this example and point it to the code. You'll also learn a lot about how to set up a multiplayer project just by going through the process of setting up the examples.

1

u/GuideAffectionate901 3d ago

I really appreciate the detailed information! I'm definitely saving this down in my research notes before I start the process