Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Realtime Multiplayer Game with firebase

Tags:

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

like image 708
Gerus Avatar asked Dec 01 '20 11:12

Gerus


1 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.

like image 89
spydon Avatar answered Sep 30 '22 19:09

spydon