Hi all
Does anyone have any tips on creating a multiplayer game? I've been coding for about a week now to just get some basic functions to work. Although the programming isn't a Java Platform, i thought i'd ask here anyways since it's pretty relevant to every language and java is what i'm trying to eventually cross over to.
How i'm interacting with clients and server is that a client moves their character, and every time that their character move, their x,y,z world position is sent to the server, and then the server send out that coordinates to everyone that is playing the game.
Well it turns out that this method is completely insane!! There was so much lags that it made the star wars introduction seem like it was in double time.
Does anyone have any tips on interacting with the server in a multiUser game? Such as what should i send to the server and send it in which ways to make it more efficient. thanks !
Did you check out the flagrush tutorials? I believe the higher ones deal with networking and JGN…
yes i've looked at it, but i haven't gone through all of the FlagRush lessons yet. I'll look into if that's you're recommendations
hey darkfrog,
i have this error becuase i don't have it in my packages. How do i get it?
import com.captiveimagination.jgn.JGN;
etc…
etc…
etc…
I would say you check it out from:
http://jgn.googlecode.com/svn/synchronization/jme-networking/
You need the JGN API:
http://jgn.googlecode.com/svn/core/trunk/
And you need the jME-Networking synchronization project:
http://jgn.googlecode.com/svn/synchronization/jme-networking/trunk/
Those are links to the trunk in SVN, so just check those out and jME-Networking has dependencies to both JGN and jME, but after that’s configured the FlagRush Networking example should work just fine.
You probably want to look at all those examples for flag rush people are posting. I am new to java and jME but not with game programming. The question you raise is a good one and there are different ways it is handled.
One method is that the server does not send the coordinates every time the player position has moved, but sends a postion, a direction and a speed when they start to move. The clients then update the postion based on the speed until receiving a message that the player has changed direction or stopped.
Another thing is you do not want to send the postion for every player to everyone in the world, only to those that can see the player. For a small map this may indeed be everyone. For larger maps it will not be. You need to determine the visual range of a player to determine when to send the message. I know in my C++ I used to have a function such as, sendMessageToPlayersInRange( Message, Postion )
so I wouldn't have to calcuate it every time.
There are other stadegies you might want to use to reduce network traffic. One thing I can tell you though. In the server, Never trust the client.
Serpardum said:
One method is that the server does not send the coordinates every time the player position has moved, but sends a postion, a direction and a speed when they start to move. The clients then update the postion based on the speed until receiving a message that the player has changed direction or stopped.
That's generally a bad idea because then you absolutely must use TCP instead of UDP and then lag is more of an issue for player synchronization and can have bad ramifications in flow on the client. Dead-reckoning is a way of doing similar, but by moving in the direction of the last change until told otherwise. This follows Newtons First Law:
Every body perseveres in its state of being at rest or of moving uniformly straight forward, except insofar as it is compelled to change its state by force impressed.
An object continues to move at the same rate of motion until told otherwise by the networking code. You can see this in action in games like Battlefield 2 if you ever see major lag and see tanks sliding by you at the same speed they were going when the connection issues began.