Physics Calculation Performance on Client

As a Roblox developer, it is currently too hard to run complex mechanisms owned by the client without impairing its frame rate too much.

In my case, I am trying to move vehicles via client physics, each consisting of five assemblies, for a singleplayer game; around 100 parts per car (Yes, it needs that many due to styling, gameplay and terrible collision decomposition,).

No I can not really rely on Server computation of the physics because of network limitations and especially interpolation throttling.

With around 25 vehicles running and moving, my frame rate drops from 240 FPS to barely 40 or 50.

If Roblox is able to address this issue, it would improve my development experience because it will allow me to create immersive singleplayer experiences with the help of NPCs and a lively world and simultaneously allow players for a smooth gameplay as well as making the experiences friendlier for weak internet connections.

Some quickly made up idea to tackle this would be to allow developers to customly set a physics refresh rate to specific assemblies so less physics calculations happen in total; Essentially workspace.PhysicsSteppingMethod, just manual.

183 Likes

If anyone is looking to respond to this post, an alarming majority of users who have liked this post have less than 1 minute read time on this platform. I can only infer that this post has been linked somewhere to inflate the like count to make the request appear more genuine. I would exercise caution if you wish to reason alternative solutions.

21 Likes

If you know the context, you will know it is genuine

9 Likes

Definitely not my problem lol. This is a great post.

Roblox not being hot garbage for server sided anything would be a good solution? I mean it seems like a skill issue to me.

Every other platform you go on has no issues with running physics on the server. Heck I can open clash royale and clash of clans on my phone right now and as long as I have a stable internet connection there is 0 latency.

Mobile app developers are way smaller compared to Roblox yet this is still an issue and we all want to see it fixed :slightly_smiling_face:

For now, running everything on the client is the viable solution, even if that introduces exploiters. FireAllClients is decent but it can get very confusing when you have complex scripts that you’re trying to replicate to all clients

7 Likes

As much as I agree that Roblox should definitely always strive for making their engine better, this post makes me… disappointed.

This is the most apples to oranges comparison that you could have ever made here.
All those two mobile games run is collision detection, and even though that’s a major part of a physics engine, it is also 2D instead of 3D, and most collisions are boxes or spheres.
Not to mention that the amount of objects that these mobile games would be checking collisions for is much smaller than OP’s claim of 100*25 = 2500 rapidly simulated (likely 240 hz) parts, all with what I assume to be mostly welds but definitely a few different types of constraints as well.

2500 parts having their 3D physics simulated 240 times a second is much more complicated than a mobile device calculating 2D collisions for at most 100 objects at maybe 60 fps.

No wonder a server would struggle to replicate that much… And, just remember that you can get access to this system without even paying a dime to have a server hosted for your experience, so for obvious reasons you’re not gonna get a top of the line CPU to handle all the computation.


In my personal opinion, you (referring to OP) should have a seperate simplified object to handle the physics, which then the actual car model can follow by setting a CFrame of a few meshes on each frame. I do not believe you need 100 parts, unless you’re trying to recreate BeamNG in Roblox, and even then I think you still can have a bit more optimization on that front.

…Or, just accept that Roblox will simply just never be perfect. Roblox is a platform, not just an engine. There’s other engines out there if you’re looking for something that you can truly run fully on the client only without needing a server.

Your game, as you describe it, will not be “low bandwidth friendly”, as even if you moved the physics to the client, they still need to be replicated from your client to the server, so other players can actually see the physics.
This is because Roblox chose to prioritize protecting your IP address from being discovered by other players, rather than raw performance, hence everything has to go through one server that simply isn’t being paid enough for this (this is an analogy).
I should also note that if this is a “single player experience” (aka 1 player per server) then by design you will be allocated a weaker server compared to games that need to handle more players being online at the same time.

13 Likes

2500 parts having their 3D physics simulated 240 times a second is much more complicated than a mobile device calculating 2D collisions for at most 100 objects at maybe 60 fps.

The issue in replication is not the amount of parts that are “moving”. A single assembly (a rigid body) that is physically simulated replicates its movement by passing the location of its root part to the clients (or to the server if calculated from the client) and repositioning the remaining members of the assembly by offsetting them to their root part.

Ergo, assemblies containing a lot of parts is a performance eater not solely because of the physics calculations, but mostly due to the need to recalculate the offset for each part attached to it 240 times per second (by default)

Hence, if we say we just let 125 balls bounce around on their own (means 125 assemblies, e.g. 5 assemblies for 25 cars), the performance impact will be considerably lower as there are no further members to offset to the balls.

Your game, as you describe it, will not be “low bandwidth friendly”, as even if you moved the physics to the client, they still need to be replicated from your client to the server, so other players can actually see the physics.

Supposed to be a single player experience

I should also note that if this is a “single player experience” (aka 1 player per server) then by design you will be allocated a weaker server compared to games that need to handle more players being online at the same time.

I know that; Roblox allocates a certain number of cores to a running game server (which is 1 for a 1-player experience which fully suffices for my needs) but as my post (and the title) stated my issue does not focus on server performance. I am looking for some ways to alter the process of physics calculations anyhow (for example, Roblox implemented workspace.PhysicsSteppingMethod to automatically reduce the frequency at which the physics of an assembly refreshes.)

Why not allow developers to manually lower physics refresh rate to certain assemblies?

2 Likes

Apologies, it was not obvious this is what you meant from the original post.
Telling the physics engine to force a certain refresh rate seems like a nice idea, though in my opinion, you should probably make such a suggestion more obvious in the main post.

3 Likes

I’m not exactly sure what this feature request is requesting; given that your experience is a single-player game, I can only assume that replication isn’t the problem but rather that you need to cut down on the refresh rate of physics, which you later mention in a reply. You also mention workspace.PhysicsSteppingMethod, which presumably isn’t fitting your needs; is there a reason why this doesn’t work? Perhaps you are using legacy BodyMovers (more specifically BodyPosition was mentioned in the announcement, although it does generalise legacy BodyMovers in general as generally unstable without 240hz), which forces the body into 240hz mode? Or perhaps you just have a very complex assembly that needs 240hz to solve correctly?

Given the other replies to this topic, it seems you have likely explained this in a different way on a server or other social media, per-chance could you re-post that message to this thread to provide more insight into this issue for those who aren’t coming from that source?

Dove a little into that, seems to be coming from this post in a Discord server:


I’ve had similar performance issues with autonomous traffic and see the benefits of being able to force a stepping rate, even if that may cause instability in theory.

It would be easier to fix instability issues with assemblies on lower frequencies, than blindly changing assemblies and pray the engine assigns the desired timesteps. Perfect stability is not always required either, especially at a distance in a singleplayer game.

1 Like

You also mention workspace.PhysicsSteppingMethod , which presumably isn’t fitting your needs; is there a reason why this doesn’t work?

The issue with that lies in the fact that it assigns the refresh rate automatically. Said feature will only reduce the refresh rate of objects that are very slow and very uncomplicated (talking a bouncing ball that moves at a speed of less than 10 SPS), which my vehicle system is not at all.

Only constraints I use are springs, prismatics, cylindrical, rod and hinge constraints. Otherwise, there is no body movers involved.

But I am probably going to follow your idea by only allowing physics to calculate where it’s actually important to be calculated (e.g. the car’s hitbox and the wheels). The body itself, the occupant characters and whatever belongs to it does neither have mass nor collisions. So in theory does not contribute to physics calculations.

I am going to disconnect and anchor the Body from the rest and only update its pivot each frame only if close using RunService.Heartbeat (since it runs after physics calculation and before rendering). If further away I can reduce the refresh rate of pivoting the body and if the camera does not face the vehicle I can fully exclude it from having its position refreshed.

1 Like

You do not need 100 parts per car to make precise collision, there are many ways to trick meshes into having extremely precise hitboxes, and thus, reducing your need for this. On top of that, you’re using parts instead of meshes, which treat geometry calculations differently (and thus, using meshes alone will speed up your performance).

Your issue is not that you have so many simulated parts, it’s that you have multiple assemblies with complex constraint calculation. This is less of a Roblox problem and more of a developer-sided optimization one.

Of course, having finer control over physics calculations would be good, and I’m all for it. That being said, I do want to point out that there are some flaws on your end as well.

I’ve never had an issue like this when developing my car game.

I personally use:
WeldConstraints & Custom Collision Model
(To reduce the amount of parts with collisions into a single transparent mesh)