I am currently trying to integrate a multiplayer option into my unity game with photon networking.
However, I do have some questions: I created the GUI with Unity's new GUI System. I am not using OnGui at all.
What I am trying to do is let a user create a room. After he/she created a room, the user will be redirected in some sort of a "waiting room" in which he waits for other players to join.
How is something like that done? All the tutorials just basically cover up how to jump right into a game. But what I want to do is get them together inside this "waiting room" and start the game (by switching the scene) once max players is reached.
I am able to create a room in the editor. I also made a build so I can test it out on my laptop. I tried to show all rooms inside an update(). But it won't show any rooms at all although I've created one.
I think I'm missing out on something, any tips?
Thanks!
What prevents you from using Photon lobby system? Player created the room sits in the room and waits while other players in the lobby choose which room join.
If you cant use the lobby system then just loop through the amount of photonplayers and see if there is only one of you in there.
if (PhotonNetwork.playerList.Count == 1) Teleport_To_A_Waiting_Zone();
Photon doesn't have a "waiting room" or any sort of pre-room lobby.
When not in a Room:
- You can get the list of rooms, and call create/join.
Once you are in a Room:
- Well.. you're in the room :)
I faked a "lobby" for one of my games by using a "custom property" on the room", when the room is created you can set a property such as ["roomState"] = "notready"
Then when all the players are in the room, change the state.
Your main loop could check the property and if it's not set, then just wait or exit the loop, etc.
Related
I'm working on a game that requires player matchmaking i.e. putting 2 players into 1 battle room.
While there are few players online in the game this is not an issue, however if we assume scenario of 1,000,000 players online at a time, who are all trying to matchmake, then picture becomes more complex.
Assuming following flow
My first instinct was to
When player clicks "play" call cloud function that checks if "open" battle room exists.
If there is one open, place player in it and start the battle or set battle to be active.
In case there wasn't an open room, we create new one and wait for another player to join.
However I see a lot of issues here given that we have 1,000,000 players who would be performing this action. For example, while performing step 2 and setting room to be "active" we might be pushing more players into it during the time those requests resolve?
If you want to deal with concurrency, I think you should use transactions to perform this action (adding a player to a room). That way, you ensure to check if the room is still open before adding a player in it. If 2 players start a matchmaking at the same time and find the same room, then only one single player will be added to that room
https://firebase.google.com/docs/firestore/manage-data/transactions
As far as I understand I can suggest One way to make it easier is have state of a user itself instead of calling cloud function to create room
Make user state like active, online, offline. When a user press play set its state active.
Call a query to fetch user where state == active , limit to 5(example).
start a transaction to match it with first user if succeed change status to playing for both else if failed ( you got matched to someone else or player you were trying with got matched to someone) check next player.
If during this you should be always observing your own state if it changes to playing because someone else matched to you then straight head to game.
Lets say I wish to track
User action - game he played - which area he stays - his house number.
If I were to track these event actions in Tabular format, it would look like:
UserId|Game|Area|House|Timestamp so on.
Then I can always run SQL queries if I want to answer few business queries. Like
1. In a given day/week, who is the most active User
2. Which game is most-played?
3. Which area plays most events
4. Which user from which area are the most active
Whats the best way to capture this using Google analytics? Will custom dimensions be useful. Or GA is not suitable for this kind of insight?
Thanks.
First of all, the house number is too precise, it would be against GA's ToS.
In GA everything is captured in "hits", you can think of this as one "row" of data.
Let's look at what you wanted to find out:
Most Active User? - This depends on how you determine "Active". Is it the longest Session durations? Tried most games? Most logins? Most sessions? To track a user, you'd need a User ID tracked.
Which game is played the most? - Again, what is played the most? Longest time in game? Most "start" games? This would require you to know the Game that was played and when someone started playing
Which area is most active? -This would go back to the definition of active, the region information is needed along with the active definition
Which users are most active in an area? Same as above, the user would need to be identified and area
To determine which Custom Dimensions (CDs) you want, let's look at the example data points you want to track and try to determine the scope and if it already exists as a standard dimension:
User ID - this is obviously related to the user, makes sense to be user-scoped
Game - This is a tougher CD. I would think that in a single session, users can play multiple games, thus I'd think you'd want this to be hit-scoped.
Area - GA already provides this based on the ISP
Timestamp - GA already provides time dimensions
From above, we can determine that you need to create two CDs, one to track User ID, the other to track the Game.
You can also look into using the userid feature in GA for cross-device tracking.
I'm currently making a online mobile game. It's like an online Idle Clicker.
In order to save the data I will use firebase. I'm still deciding if I should use the "Realtime Database" or " Cloud Firestore". (If any of you could help me too I would appreciate).
My main question is: When should I save my data ?
Saving the data every second is crazy because I will spend millions of euros. Even saving the data every minute seems not a viable solution to me.
I have searched and I can save the game everytime the user press the Home Button to leave the app. What if the user is playing and the phone dies?
Is there any other better solution that I am not thinking of ?
Thank you very much, Gonçalo
I would use OnApplicationQuit() for this. It's called whenever your game is closed. It won't be called if the device loses power though, so if you're worried about that you could start a timer when the game is opened and do autosaves every 10 minutes or on certain scene switches (if the player exits to the main menu for example).
This thread has more info on the topic that you may find useful.
I am making an app.. I mean a game type app. it's a quiz app where two people can
pair them up and can answer questions one by one and so on.
what I want is:
I want to make a virtual room,
when USER1 want to play he will click search competitor, a virtual room with random string key will be made with one player.
then when USER2 will click on find competitor button his room will also be created and he will also search all rooms created before him, if any room have less than 2 users then he will join that room and start playing.
I am new so I am not sure if that is good approach but that's all I have planned.
how to count childs of a node (node that we does not know whats its key..
)
see attached image
please find image here
Good start. It's always best to articulate precisely what you want before your start coding. It sounds like you have a pretty good idea of what you want.
I would recommend using Firestore and firebase.auth, even if only anonymous, so that each user can have 'state' and univeral id in their app. In other words when they close and re-open the app, the app keeps a universal id, uid, for them.
If I understand your requirements:
each user can have more than one room
each room has a max of 2 users
Scalability
As far as searching existing rooms, this will not scale without some categorization. What happens if you have 1,000 rooms? How will users search all that? So you would want to add subject matter, or tags, to each room. That way you can query where("tag")==chosenTag.
Basically each virtual room has fields identifying the 2 users (uid's), AND has subcollections - each collection has a document
uid has fields (accountCreateDate, favoriteColor, AND the uid of each room (as a key) they engage in where the value would be an integer where, for example (1== awaiting response, 2==closed, 3==whatever).
Firestore Structure
users(collection > userUid(document containing aboce said)
rooms(collection) roomA(Document w field identifying subject/name) AND sub-collection containing a doc for each pair of participants.
I will create a biped robot soon, i will add speech recognition and stuff to it.
I want it to find in my house. Is it possible to create like a map or something where i mark the
places in the house with numbers or something and then make the arduino robot
read it, so ex. when i say: "Go to your room" (the arduinos room = my room) it will go
to it's room (my room) automaticly.
UPDATE:
Is there a gps module or something that i can modify like i want so my robot
can find in my house? So i can mark where it can go and where the rooms are
and so i can program it to go to ex. my room when i say so, and it will find to my room.
There are many different ways of attacking this scenario. If you are talking a map it might be worth generating a measurement system whereby you can use an array of units to allow your robot to navigate the house. I think you will run into issues over time with unexpected variance so the large part if navigation code would have to tackle calibrating against a known map.
The advantage of using this method is that you could have it "learn" a new space by mapping a new array against your units