Minimising load on server with scripted suspension

I have created a scripted vehicle chassis that uses VectorForces and raycasting for my game that has been working a treat until now.

When the car has no-one driving, the server takes ownership of the vehicle and updates the suspension, but i have realised that this has a fairly large performance hit on the server. I would go from 100ms ping when there is a driver to 800-1500ms ping when the car has no driver and the server script has taken ownership.

I was thinking about a sort of faked suspension which would use a BodyPosition and BodyAngularVelocity (like the jeep in one of the starter roblox places you can get) which keeps the vehicle in one place, but the big problem with this is it doesn’t handle well over hills/ramps. If you were to drive to a ramp or hill and then exit the vehicle, the vehicle would sort of hit the ramp and bounce backwards which is not ideal at all. This game i’m making will include players bailing out of their vehicle while driving as part of gameplay, so this is quite important.

Another solution is going purely with roblox constraints, but im not sure how reliable this can be. Ive had problems in the past with wheels glitching or disappearing etc.

Is there any better solution to this problem? any help is much appreciated :ok_hand:

You could simply control the VectorForces and RayCasting on the client. This would allow each client to render and process his or her own vehicle chassis.

Do you mean control the forces until a new player enters the vehicle, then transfer the ownership?

Why control the suspension when no-one is in the car? Simply add a listener on the client for when the players character enters a vehicle seat, then when that’s fired run your physics calculations on something like RunService:RenderStepped(). When the character leaves the vehicle seat, disconnect. This will remove the load from the server when nobody is driving, but will also allow the vehicles to run extremely smoothly on the client because the client is doing its own calculations.

Transferring Network Ownership should also be done on top of the client sided physics calculations. I recently created a vehicle chassis using Roblox’s built in constraints however the few calculations that are made are all made on the respective client.

I need to control the suspension if no-one is in the vehicle because if i dont, the car just collapses because theres no suspension holding it up.

I need a way to continue updating the suspension when there is no driver without straining the server so that it doesnt do that, and so that if the car is moving when the player has exited, it will continue to move correctly.

Gotcha. So in this case you have a few options.

  • Continue to use the lastDriver’s resources to calculate the physics until a new driver enters the vehicle
  • Anchor the vehicle until a new driver enters the vehicle
  • Take advantage of the new sleeping part behavior

Ill try out using the lastdrivers resources for now since I need the vehicle to continue to move, so the other solutions you proposed wont really work out. Although two problems im worried about

1: if the framerate of the lastdriver becomes low it could result in the car acting strange to other players.

2: if lastdriver leaves the game, who should take over ownership of the vehicle?

It’s a big possibility that the vehicle would start to act oddly for other players but players aren’t focusing on dormant vehicles right? It shouldn’t be a huge if a vehicle is a little jittery. If the vehicles are dormant for a small period of time, physics calculations on the server wouldn’t have too big of an impact but there are better options.

If a player leaves the game you could simple choose the closest player to then elect as the resource hub.

True that people arent really paying attention to them, but in extreme cases, having a fps lower than 10 can result in the vehicle flinging. I could probably have the server choose other players with better resources to take over for players with low fps, but i dont want to end up with people having to take over 8 different stationary vehicles at once.

Just curious, what’s the point of having stationary vehicles with no players in them? You could remove them? Does each player have their own vehicle?

In this game, vehicles are spawned at points in the map until they are taken, which is when another will be spawned after a minute or two passes.

Vehicles will be despawned after time passes once the driver exits if there is no new driver after a while, but some vehicles are armoured (tanks and things like that) and would be used as cover from enemy players, so i would want to keep them for as long as possible.

The best way to do this is simply weld the vehicle together therefore it won’t fall apart when a player exits. Only calculate physics when a player is driving the vehicle. Have roblox constraints setup but disabled waiting until a player leaves. When the player leaves the vehicle, kill the client physics calculations and activate the constraints.