Physics Based Vehicles in APB: Reloaded

Started by
3 comments, last by hplus0603 6 years, 4 months ago

Just how did they do that? Currently up to 80 people can be in the instance at any one time, they could technically all be in cars and drive them, ram them into eachother and so on and all of this is processed clearly with physics. But to prevent cheaters, it must be done server side.

So my question is, how does the server perform all those physics calculations so quickly and serve them back to the client to be seen and interacted with on the fly? Could anyone go in-depth with me on exactly how this is happening?

Here's a solid example of all of this for you guys:

I'm a long time player and I can't fathom how they pull this off programming wise. I even know what goes into their servers.

http://apbreloaded.gamersfirst.com/2015/02/new-apb-servers.html

So just how hard would this be to recreate in Unreal Engine 4?

Edit: Here's another video for LOTS of physics calculations in collisions and such.

 

Advertisement

Maybe they don't simulate them on the server, and it just replicates client movement through to other clients? 

Or maybe it does... Simulating 80 simple vehicles at normal framerates isn't hard. Naively transmitting their state would use a lot of bandwidth, but vehicles tend to follow pretty predictable paths, so you can reduce them to a very sparsely Sampled key frame animation / spline and get the same result with a fraction of the data. If each client is also running the physics code to predict the movements of each vehicle, you can transmit even less data when user inputs aren't changing, and focus adding keyframes when they are changing. If the vehicle simulation is deterministic, you can just send only user inputs and timestamps most of the time, with very occasional position/orientation/velocity keyframes. There's loads of approaches to each part of the problem. 

4 hours ago, Hodgman said:

Maybe they don't simulate them on the server, and it just replicates client movement through to other clients? 

Or maybe it does... Simulating 80 simple vehicles at normal framerates isn't hard. Naively transmitting their state would use a lot of bandwidth, but vehicles tend to follow pretty predictable paths, so you can reduce them to a very sparsely Sampled key frame animation / spline and get the same result with a fraction of the data. If each client is also running the physics code to predict the movements of each vehicle, you can transmit even less data when user inputs aren't changing, and focus adding keyframes when they are changing. If the vehicle simulation is deterministic, you can just send only user inputs and timestamps most of the time, with very occasional position/orientation/velocity keyframes. There's loads of approaches to each part of the problem. 

So I'm sure all of what you say is true, but for each client running the simulation, does it not make sense that the server still has to calculate for the clients to ensure there's no hacking going on? Then again, basic checking could just ensure the client is too far from where it should be and then let it keep going otherwise, or run a correction every now and then if need be.

The part that tricks me the most is the collisions. I can't have clients handle that because if they all did their own calculations, wouldn't it be out of sync perhaps? I figured the server would have to handle that.

Also, just how much stress does a physics calculation like that take server side? If it's not as crazy as I believe, maybe it's not that bad. All I need to do is achieve <50ms, ideally 35-40ms.

They use Unreal 3.

I believe they run physics on server and client, and send control inputs from players to all players, and round-robin updates of the server simulation to the client.

This means that someone may fall out of sync for a little bit (if some input is missed,) but will be brought back into sync at the next full update.

Physics updates aren't particularly expensive -- you need position, orientation, velocity, and spin. You could easily encode that into 3bytes*3 for position, 2bytes*3 for orientation, velocity, and spin. 27 bytes per entity. Doesn't matter if it's a car, or a person, or a missile, or a piece of debris (assuming you care at all about that debris.) Generally, you'd only send the POVS for the main chassis, and let the wheels and other animated bits just animate based on the local physics, without making things like suspension extension be the exactly the same on all clients.

Finally, regarding server load: The clients are calculating all those cars, too. AND all the sound and rendering, that the server doesn't have to deal with. Why do you think the server wouldn't be able to keep up?

enum Bool { True, False, FileNotFound };

This topic is closed to new replies.

Advertisement