I have run into an issue while making a quite large game if mine, I’ve recently started putting our builds and scripting together in one place. I have discovered that scripts that make use of server sided physics essentially don’t work (or well, the physics render about once per second). I have experimented around and found out that the roblox terrain is causing this, does anyone have a way to reduce the giant physics lag that comes from roblox terrain other than to completely rebuild it as a mesh?
Thanks for reading, hope to see your solutions below!
Are you sure it’s the Terrain?
You mentioned ‘putting our builds and scripting together in one place’ but if you put a lot of physics based models into a game (big or small) it can slow physics down.
If you have your large terrain place with a couple items and it doesn’t lag then add your builds & scripts to it one at a time to see which is the item causing the most lag. If you find one or more items that cause physics to lag then look at those items, not the terrain.
What causes lag has a lot to do with what specifically you are doing and how you are doing it. This is a bit too vague to really tell, it could still entirely be your code causing the lag, for example, if you are looping over many things many times.
It could also be that your code is doing something different when the terrain is present by your own design (intentionally or accidentally), but that doesn’t necessarily mean that the terrain itself is the cause of the lag.
What exactly are you doing with angular velocities? What particular properties are you using, how are you deciding what to set on them, and how often and on how many things are you setting them?
You could also take a look at the microprofiler, if you go into the Detailed view and pause it while the game is lagging, you can try and isolate what the biggest bars in any noticeably long frames are, and even if that doesn’t tell you exactly what the lag is caused by, it helps you narrow down what the actual cause is.
The only reason I could guess that the terrain could cause additional lag is because there is more for objects to collide or interact with, and though it’s still possible, I’m not sure why terrain in particular would cause extra lag from physics, so my first guess would be that it’s not really the Roblox terrain, it’s almost always more likely that lag is something in your code rather than Roblox.
My code applies velocity to wheels of my chassis on physics step, and there is nothing wrong with it, e.g. I was testing with about 20 cars at once and it was runing just as smoothly as with one. The issue came when terrain was added. (This could be caused by the waves on the water for instance), but I didn’t do enough in depth testing to know whether that’s really the issue.
As stated before, Terrain doesn’t usually cause lag.
I use physical Constraints on my suspension vehicles with little to no lag. The biggest lag I get from my vehicles comes from a tracked suspension ‘tank’ chassis, but that is because there are about 60 MeshParts total in the tracks, with 3 suspension wheels supporting the vehicle on each track, 2 end wheels on each track and a sprung ‘suspension’ wheel on top to keep tension on the tracks. You can see the results in my suspension test game.
The other vehicles run very well and very stable on Terrain, even at high speeds (you will see a mouse click icon above many vehicles in the game to switch between low and high range speeds). I know that if you have 40-50 suspension vehicles with steering, SpringConstraints, HingeConstraints and PrismaticConstraints then things start to get a little bit laggy.