Realtime Multiplayer Game with firebase
Asked Answered
T

2

6

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

Trilby answered 1/12, 2020 at 11:25 Comment(2)
This has absolutely no relationship to Firebase. You just use Photon (say) - you can have it running in five minutes. Enoy.Siret
Note too that Firebase has no connection to realtime - you may be thinking of PubNub, the world's major realtime network, which is amazing (click over and try their demos). But if you want to make a realtime MP game, you - of course - just use the many systems available for that.Siret
S
6

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.

Subcartilaginous answered 1/12, 2020 at 13:58 Comment(4)
I don't downvote, but this would be sort of like suggesting to someone who needs a spreadsheet to make a note of their spending at Starbucks .... that they learn software engineering and then develop an SQL database from scratch, and use that :)Siret
@fattie since Flame is a quite simple 2D game engine, depending on what type of interactions and accuracy that they need between the players it doesn't necessarily need to be that hard to roll your own solution.Subcartilaginous
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. 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 itSiret
If you edit your answer to add that I will remove my downvote. :)Subcartilaginous
S
-1

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.

Siret answered 1/12, 2020 at 14:16 Comment(3)
You are answering the question for an unrelated game engine.Subcartilaginous
hi @Subcartilaginous ! "If this is totally unthinkable what could be alternatives?" It is utterly unthinkable, and I've explained wot to doSiret
You are correct that it is what is written, I don't think that is what he meant though (re-writing/porting his whole current game). It is not "utterly unthinkable" either, it has been done before in the Flame community.Subcartilaginous

© 2022 - 2024 — McMap. All rights reserved.