I have GameCenter functioning in my new game, which is a racing game.
But, i am wondering if you can use Unity Netwroking RPC calls and network instantiate with it ?
If you can, then what are the steps that need to be taken to do so.
Other wise, i can get two players to go against one another by sending messages through GC server, but i can’t get a third one going.
This is my setup.
Two cars, one is controlled by the user and the other receives position updates from the networked player.
Very basic, so each controlled car send messages out with it’s position and rotation to the networked dummy car. So both players actually are racing and all.
Both have the same script, so if i add a third player, things get complicated and i tried everything, and nothing seemed to work. Basically since players are using the same script, how am i going to tell one to send messages to the first dummy car and the other to send messages to the second dummy car, if i tell one to do one thing, then all will follow.
Maybe i can’t get the concept quite well.
If someone can give an idea or share an experience, it will be greatly appreciated.
Add script and networkView to car prefab. In this script check if owner of networkView is u then send car positions, if not receive them and update car position.
How can you check if it’s you!
Each player on his own device in the network, will think it is him, so they will all send.
The dilemma is that each player on his own device will be player ID: 1 and everyone else is ID: 2 then 3 and so on.
So there is no way to check if say you are ID: 2 to send to dummy car number 2, and if you are ID: 1 to send to dummy car 1, since each player will think he is ID: 1 thus all of them will send to dummy car 1.
If say I change the script to send to dummy car 2, then they will all do the same and send to dummy car 2.
Do you get what I mean?
Then your game logic is flawed and you should fix it. If you make a multiplayer game the server has to set the ids and send them to client, not each client themselves. So you have to fix that first, before you can go to the next step.
First rule of server-client-development: Never trust a client.
Let’s not forget that we are talking about networking with GameCenter.
So I can’t touch GC’s server.
All I have are the clients!
So they are the ones that will check IDs and act uppon that.
Do you see the delimma?
GC is GameCenter.
That’s what I am trying to say,
When networking with GC, how do you deal with clients, if you can’t control the server.
So each client thinks that it’s player1, thus there is no way to run different conditions through since all clients will end up doing the same.
When u instantiate client yourself assign isMyCar = true; in client script and when other client does it: isMyCar = false;
then check if it isMyCar == true send positions and if not move car according to received positions.
If that does not work show your current client script or post how u instantiate, send and receive positions and I will change it to handle clients…
Unless im mistaken, youre just using the GC as master server: whoever connects first is automatically the real game server: and when you put a networkveiw on Each vehicle: it will take care of it: it knows which client instiated which prefab and will only have your car with its network id: which is the same across the network: you may be b but my car is c and bob’s car is z ajd its synced accordingly: network.isMine will work
Just in case you guys don’t know,
Unity’s networking stuff doesn’t work with GameCenter,
So if you do network instantiate or other things that has to do with RPC calls, your just speaking English to a Chinese person!
GC and unity networking are completely different.
What GC gives you is an open socket between you and the other connected player/s.
Then you will have to come up with your own protocols to handle data back and forth.
Having said that, the idea of setting a Boolean might work to kind of distinguish which player is which and then act on that.
I will give that a try.
The way I have GC working for me is by using sendmessage with a set of position and rotation, which is received on all other clients then decode the message and act on that.
My main problem was trying to get more than two players going, so I will try the setting a Boolean then have all clients send their condition and based on that, I can direct their position to a dummy car all over the clients.
I am trying to do this very thing now and haven’t quite figured it out, but samshosho I believe you are quite right about GC and Unity Net being two entirely different beasts. Let’s say GameCenter is used to create a match using standard GameCenter matchmaking, and lets say you connected a single client to a single host successfully, as far as GameCenter is concerned you have a match in progress with 2 connected devices. However, If you then examine the built in Unity networking object, say by examining Network.connections, you would see a zero. As far as Unity Networking is concerned, there are no devices connected since GameCenter does not utilize Network.InitializeServer() nor Network.Connect(), therefore Unity networking doesn’t believe you have a networked game.
Theoretically I am told you can conduct a “Hosted” game… which basically means you have GameCenter UI perform the matchmaking… but to resolve the device connections and perform communications between devices in a “Hosted” game, you have to write a bunch of low level networking and messaging code that resides on a central server you provide. You then, in theory can have GC get you the players, and you manage all the comms between the players with your own network servicing architecture. I just haven’t figured out how this works, and there is like ZERO data on the subject.
I’m also having this issue. I was thinking though -
What if we use Game Center as the matchmaker, so it finds players that can connect - and then it passes the Hosts IP Address via the SendMessage. Once the hosts IP address has been sent, GameCenter then disconnects (or stays connected, this part is irrelevant). But anyway, now the clients have the IP address of the Host, you can then pass that on to the Unity Network Protocol as a standard ‘Network.Connect(IP, Port)’.
Would this work? I guess, theoretically it’s okay right? Would apple allow this?