Realtime Multiplayer Game with firebase

Viewed 4757

I just created a mobile game with flutter and would like to extend that to a multiplayer online game. So I thought about making it with firebase. I'm rather new to this domain so I hope my questions don't sound too stupid.

As the characters in my game move around fluidly I need to update their positions at least once per frame, so in case of using firebase I would need a cloud function that runs like 60 times per seconds and never ends. This function would then take all the objects in the game (which are stored in the realtime database) and update their positions according to their speed. The updated values are written back to the database to which the clients listen. They update the values in the game and render the objects at the correct positions. Whenever a player interacts with the game somehow another cloud function is called to handle that and update whatever is needed.

Is it possible to make something like this and does it make sense? It does not sound very smooth to me using cloud functions in this way but I don't have another idea of implementing it. And how would it affect the costs? Sound like a lot of function invocations and db reads/writes..

If this is totally unthinkable what could be alternatives? I wouldn't mind too much using another db and or framework to make the game itself.

Thank you very much

2 Answers

Communicating positions etc through a database won't be fast enough for you to do it 60 times per second. You'll have to use some form of mixed UDP and TCP solution and unfortunately that doesn't exist pre-built for Flame like it does for some game-engines, but it might not be too complicated to build one yourself depending on how complex your use-case is.

Like @Fattie suggests, it could be a good idea to try out if PubNub works for you.

Update: There is now an early stages Nakama (Open source game server) integration for Flutter here.

Firebase has utterly no connection to what you are trying to do.

You just use Unity and one of the realtime-multiplayer services - like Photon.

It is inconceivable that as a hobbyist you'd start from scratch and try to write realtime, interframe, predictive quat. networking!

In five minutes ...

https://doc.photonengine.com/en-us/pun/v2/demos-and-tutorials/pun-basics-tutorial/intro

It takes 5 minutes to download the Photon/Unity demo and be playing a realtime multiuser game with robots running around.

enter image description here

You then just learn how to add guns or whatever and add your own models.

Flame ...

Flame is spectacular BTW. To do a R/T MP demo with Flutter/Flame, I'd suggest just using PubNub, which would take no time.

http://pubnub.com/developers/demos/codoodler (all of the demos are terrific). It's the world's major realtime backbone, nothing is faster, they do Flutter so - that's about it.

Related