I have built a nice asynchronous C# UDP server for a game I am working on (using VS2008) and I have hit a bit of a hurdle…
I am creating the game client within Unity3D, I have created the login page, it works with the server, the server creates and holds said session, and returns if the player is already online, if the login credentials are incorrect, or if the login was successful… If the login was successful it loads the next scene which is the game scene, and hides the loading screen… This all works perfectly.
The issue I have is… one of a quite awkward matter…
The only third person controller script provided is in UnityScript (Let’s face it… It’s basically JavaScript) and I have not been able to find any information or documentation stating that UnityScript is capable of sending UDP packets.
I need to ensure that the client sends a UDP packet containing the character position only when the character is moving, which will then be stored in the online players (RAM) database on the server so that character positions will be sent to other players.
I can think of a few ways to do this…
I can create an void Update() function in a C# script that checks to see the player position every 20ms or so… And if the position has changed it sends a UDP packet to the server confirming said movement…
I can ask very nicely for someone to create a C# Third Person Controller script which I can just latch on to my existing player object, and be done with it.
I can find a way to have this UDP packet to be compiled, and sent within UnityScript.
Anyone able to assist me in this matter ?
Everything so far has proved to be very efficient, and work well. I don’t particularly want to waste CPU usage on the client’s end to check to see if the character is moving every 20ms. Naturally there is a lot to do programming wise. For each packet sent to the server from the client, at least 3 packets needs to be sent back… In the situation that a player moves, that specific player will NOT receive the movement confirmation packet. Only players within a specific view distance to said player will receive this packet.
I don’t see what this has to do with the 3rd person controller script? You just need to consider how to design your game messaging.
I’d create an Observer, of all game objects. Register all messagable objects with it. Including your 3rd person controller.
This knows all positions, etc of all entities.
You then have a messaging service, and the observer tells the messaging service the entity updates.
Ideally you’d put another layer inbetween these 2, MessagingStrategy, that stipulates what kind of messaging to do, Poll, OnChange, etc, this bit is the filter bit, logic for 20s update, etc. So you could have like different Strategies to use depending on what needs to be sent.
It’s all good. I created a Co-routine to handle the movement packet while instancing a function that sends the packet VIA UDP.
This is all sorted with a big smile.
I did a bit of research into what other people had been doing, and I figured out a way I can smooth a character’s movement with minimal packets, down to less then 10 packets per second when the player is running Not bad.
Thanks for your input Wolfos, and CrazySi. I didn’t really want to reinvent the wheel. I’m more then happy with the existing controller script, it will likely be revamped when there is a need for it. But for the time being, I need t focus on my deadlines and ensure things are bug free. Once I meet my milestone, I can look into tweaking things, like adding strafing, using the Right mouse button to drag the camera to rotate around the player.
I would love to see how you did it, I’ve been tasked with creating a third party server for unity (Which means i cant use ANYTHING Unity gives). And I’m quite stuck since I’ve only been working with networking for about 3 weeks. i’ve been able to write a chat program, and thats about it. I cant get a hold of the transform of my player object or anything.
So to get back to what i said originally “I would love to see how you did it”. ^^