Online Gaming

I know that this is not yet Unity-simplified, but I was wondering how to make a simple online game. I want to be able to get and receive info from a server every frame so that I can have multiple people playing through the server, each telling what their information is, and each reading what others’ information is. Using .NET or the WWW class, how would I do this?

Oh my god… ok, this issue has been brought up now at least a dozen times! It’s seriously time to make a tutorial for an online game with multiple users. Whatever it is, no matter how basic, too many people are curious about how to make this work and it’s not enough anymore to say “look at the WWW class.” Has anyone used this yet besides posting highscores online? If anyone has figured the coding out I’ll gladly lend my artistic skills to making a solid tutorial.

Yes! Someone finally cracked! I keep looking at the WWW class, but it seems like it would be way too slow for any kind of reasonably cool online shooter. Many thanks to whoever takes up this post!

A multiplayer version of the existing FPS tutorial would be great. Maybe make the bots optional.

Including a simple server browser (probably not unlike that web-based high score list I suppose) so you don’t have to know the host’s IP address would be very helpful.

I propose a simple racing game with around 4 players. Or, I’m currently working on a Tron LightCycle game that would be perfect for multiplayer use. I’m thinking something simple where the goal is clearly defined and a “winner” could be coded simply enough.

heh, good luck coding that stuff guys… Right now you would have to write your own networking and synchronization code using .NET. Very possible, but very hard too.

If your game is simple enough, a look through the .net docs and a bit of creativity should get you a long way, but if it is more complex than a simple board or arcade game, better get some aspirin. :wink:

We need some more built-in support for this kind of thing. BTW, did you notice in the screens Nicholas posted recently when David was asking for cool screens, the top menu of unity had a “Server” entry. Whether anything like that is in the works currently or not, it is interesting none the less.

-Jeremy

That’s exactly the point though man, enough of the arcane code… “good luck everyone with the WWW class” mentality. Just a super simple example of online play… PONG! Seriously, show me how Pong would work online and the rest could grow from there.

I have been looking into this and its not cut and dry. From what people have told me and what I have learned networking is hell. The www class I dont think is capable of making a real time game work. You would need to use the .net stuff and you need to choose wether to use tcp or udp (depending on the purpose). For real time purposes you can I guess only send a packet like a couple times a second which is not every frame. So then you need to write some script to smooth or anticipate what the player will do. Any ways its not easy and you have to know your stuff. For some thing turn based the WWW class could probably work otherwise it seems like a chore.

Bill

The WWW class cannot (well, should not) be used for a multiplayer game like that. You need .NET. The WWW class just handles web server interaction. :wink:

Showing a demo of multi-pong (sounds cool eh?) would only help so far. It could be done synchronizing the paddle positions and ball position/velocity (one machine would have to be the server to keep the ball physics from screwing up).

Ok, so that’s cool, but try applying that code to a platformer with many physics objects and many players or a FPS, or a racing game where you have car-on-car physics interactions.

I guess it would sorta be like AI. It would rock to have a set of helper classes for stuff like pathfinding and such, but it is mainly game specific. I do agree that we need an array of helper classes for networking though. Especialy for physics.

-Jeremy

lol, Bill beat me to most of it.

-Jeremy

Ok, cool, I’ve used UDP before for LAN type interaction with Max/Msp. But the point is the WWW stuff in Unity is too hard for most people to work with. And you need a ping rate much higher than a couple times a second. If this is truly possible in Unity we need a good example to prove it.

lol, please stop calling it the “WWW stuff”. :wink: The WWW classes in Unity are only used for simple server communication (request a website, return the page as a string). They aren’t meant for anything else. .NET is there if you need to go further than that, and to be honest, OTEE already gave us networking with access to .net. They just didn’t make an easy “one-click” solution, and there probably isn’t one either.

Go for it man! :wink:

I assume a messaging system would be easy enough to write, the trick would be keeping it all syncronized with the server. Even so, you would have to allow for latency like Bill said.

I would love to see OTEE add easy networking to Unity, but it really is up to us and to what game we are making.

-Jeremy

I think something useful for a wide range of games would be possible–something on the order of a list of variables and properties that get kept in sync, with some options for HOW each one is synced. With physics, for instance, you could sync an object at the moment of a collision, but let it deviate the rest of the time.

Keeping perfect sync is REALLY hard, though. I made a realtime LAN game once that never got out of testing because the game state would get just a LITTLE bit out of sync (I never knew why)–just a tiny difference in the position of a character–and the “butterfly effect” would eventually have totally different things happening on the two computers. I’m sure I could have debugged it if I’d stuck with it, but it was no picnic.

Lol, hey, I’ll keep calling it “stuff” until someone actually creates something else with it :wink:

No one has yet, and if you want to contribute some .net multiplayer concepts then go ahead, but just admit that no one else has pulled it off so far and all I’m saying is a good example from the dev team would help a lot towards how it’s supposed to work? No?

Or if you have it figured out then let’s make a demo for everyone else to learn from.

Well, I belive Joe has done something like that for contract work. He posted an example of it to help a guy with another problem…sry can’t find the link but I belive he posted a sample app. Either that or I was dreaming again…dang wierd sleep cycles… :wink:

It is possible I am sure, the fact that no one has pulled it off yet is simply because networking is hard. And with Unity we have to write our own networking. I don’t think it’s a question of whether it’s possible or not, it’s a question of who has the skills and time to write it. I don’t. I could maybe pull off the pong example, but I don’t have the time. Anything beyond that and server communication is beyond me.

-Jeremy

The main problem you will have, is needing a server that will let you run custom code to handle the message passing.

Code for sending and receiving messages isn’t all that difficult and there are several open source socket servers if you search around.

Hey guys - guess what? I’m trying to teach myself some .NET stuff. I could probably even get away with what I learned from the client-server example project to make a (very very) simple game. If I suceed and am (very very) confident with what I have done, I commit myself to answering your questions with a tutorial to go along with whatever files I come up with in my project. This will be a simple game though, with not much excitement going on.

I think the structure will be something like this: the client sends the user’s controller information to the server, and the server sends the camera’s view to the client. If that sounds stupid to anyone who knows what they’re talking about, please tell me BEFORE I start working on this (that will be 2-3 weeks away). I appreciate all the help I can get.

No promises, but wish me luck!

There already is some network code posted on the tikiwiki: http://unify.bluegillweb.com/scriptwiki/index.php?title=NetworkCursor I haven’t tried it out yet, but it is claimed to work.

What is transmitted in a message would need to be changed for each application, but this is certainly a good start.

Yeah, I’m looking at that code right now in the example it comes in. You need to get the full example for it to make sense. Build the client and the server levels as seperate games, start up the server game, and then the client game, and the server should have a crosshair that is at the same position on the server screen as your mouse is in the client screen.

I’ve revised my idea about how to do the server-client application I will soon begin working on. I decided that it should really be running the full game for each person, so each person can send their control input information to the server in a FixedUpdate function, and then everyone just gets this info from the server each FixedUpdate, and all the characters in each person’s game will depend on this information to decide what they do. I’m afraid it might end up not working because of different speeds of computers, but I’ll try to do something like that.

I now have a server-client example scene working. I’m changing my ideas from those above though, because there are some minor differences that compound to make my character in one client to be way off from that in another.
Now, I am changing my file to send the control data to the server from each client and then send back the actual changes that happen (like rotation and position and player status) from the server. This way, if a client misses a packet, the game will still go on. Soon I will have a very simple example scene that I will post.

I don’t have much experience writing things so they are pretty like the other pdf tutorials, but I can certainly do the writing for the scene and code I have to help show people what they need to change to make their own networked game. I’m wondering if I could possibly write this explanation stuff and let someone with more experience polish it up and format it. If someone is willing to do this, I would be more than happy to write up an explanation. Otherwise, I’ll just post the explanation in a separate topic with no pretty pictures or side quips for advice (how embarrassing!). You can either post your commitment here or email me at elias723@gmail.com . Thanks everyone.