SpiderMonkey and Physics

Hey guys, I have been reading about networking concepts pretty much for the last week or so trying to wrap my head around it. I’m a little confused on some things.

For example:

If the server ticks physics every 100ms (10 times a second), and the client transmits his collections of input states every 100ms. How does this work with the CharacterControl? All the character control has is a walk direction. Applying the same walk direction twice in one loop will do nothing.

How does it work if one client has a latency of 200ms? Won’t he miss every other tick of the server, and thus move at half the rate of everyone else?

Any advice on this would be much appreciated.

Hi bgilb,

I haven’t done so much Networking yet.

But i would send every 100 or 200 ms the Position of the CharacterControl instead of the Walkdirection. So no movement would be lost by a higher Latency.

And with setPhysicsSpace or warp you can set the Position. With getPhysicalSpace you should get the Position.

Hope i can help :smiley: ,


That would work, but I cant trust the client with its own position.

This is a massive subject, so you really need to go read up on it (I know you just said you already did but I don’t know what articles you’ve read). There are a lot of good articles on the internet that will give you a starting point although I don’t have any links handy.

Once you have the general knowledge you will be able to ask more specific JME questions :slight_smile:

These articles are a good starting place:

Source Multiplayer Networking - Valve Developer Community

Latency Compensating Methods in Client/Server In-game Protocol Design and Optimization - Valve Developer Community

And if a few times reading through those doesn’t give you the information that you need then it may be too early in your programming skill to attempt multiplayer programming of this kind. It’s a huge and difficult topic.

I’ll just bump in here to say that you can modify the speed of every physics loop by multiplying the walkdirection.

For example you can do something like this in the control update, where you define the

actual speed of the player via the player field speed.


camDir.set(gs.cameraControl.getDirection().getX(), 0, gs.cameraControl.getDirection().getZ());

camLeft.set(gs.cameraControl.getLeft().getX(), 0, gs.cameraControl.getLeft().getZ());

wDir.normalizeLocal().multLocal(tpf * player.speed);



And by using inter/extrapolation, you can still run the physics clock at full speed and get a somewhat accurate movement

that is in synch with the server. All of this takes quite a bit of time, both to think and to implement.

You will probably need to adjust position at times to avoid going unsynch.

Also you might want to consider how important the latency compensation is for your game.