2

In my roblox game, you use a rocket launcher to destroy parts, but when a large amount of parts are being calculated at the same time, it causes immense lag to all physics-based items (including required gameplay items such as a bomb). I've tried using SetNetworkOwner to assign items to the server, but that only made things much worse.

If there is no direct solution to lowering the lag, is there any way to group physics calculations to separate the core items from the destructible ones?

Code that causes parts to be flung:

part:BreakJoints()
part:ApplyImpulse(((part.Position - explosion.Position).Unit * BLAST_FORCE.Value * part:GetMass()))
6
  • 1
    The map which the main issue occurs on is the classic "Roblox HQ" map (available on toolbox), leading to upwards of 80 parts being hit at one time. This is with the Rocket Launcher at 8 blast radius. There are visual effects, but we removed them and the issue still persisted. The parts can be hit multiple times, so they aren't able to be removed Commented May 31, 2024 at 18:51
  • 1
    Could the parts actually be destroyed instead so they can be removed and a delay for them to respawn would replace them, so that maybe it could stagger the possibility of 80 things blowing up at the same time? Commented May 31, 2024 at 18:58
  • 1
    Good suggestion, I'll attempt to implement that if at all possible Commented May 31, 2024 at 18:59
  • 1
    Good luck, let me know if it works out and I'll type up a real answer. I just recalled that a common thing people do is destroy the object, then replace it with a visual object without physics that shows the destroyed version of the object and it too would have a shelf life and auto despawn after some time. Throw in some randomization on how long it takes and you got some good staggering. Commented May 31, 2024 at 18:59
  • 1
    Have you tried using collision groups? Commented May 31, 2024 at 20:21

1 Answer 1

1

While having many parts explode and get unanchored will always result in lag because of physics calculations, they are ways to improve the physics performance of your experience.

Technically, you could just have the parts disappear, it takes away from the player's experience. Even with removing other factors like collision calculations it will suffer because of physics.

  1. One way you can improve the performance of physics is to use Adaptive Timestepping which improves performance of physics by changing the physics frequency of specific physics calculations.

    By default, Roblox simulates physics at 240 Hz. Given cycles of approximately 60 frames per second, around 4 worldsteps are advanced per frame. With adaptive timestepping, the physics engine automatically assigns parts to three "solver islands" by varying their simulation timestep, with an emphasis on 60 Hz for best performance. However, parts that are "harder" to solve will use a faster timestep like 240 Hz to ensure physical stability.

    It is also important to note that adaptive timestepping isn't always suitable if you want accuracy on your explosions or physics.

    Adaptive timestepping can improve physics performance by up to 2.5 times and it is recommended in most cases. However, some experiences should use Fixed mode (240 Hz), including:

    Experiences that require highly accurate simulations and stability, such as racing games, "destruction" simulations, or games featuring complex mechanisms like tanks.

  2. Another optimization you can perform is to set the FallenPartsDestroyHeight which dictates how low a part can fall being destroyed. This is especially helpful if they are a lot of parts falling off the map because the parts can be removed sooner resulting in less physics calculations and lag generally.

    This property determines the height at which the Roblox engine automatically removes falling BaseParts and their ancestor Models from Workspace by parenting them to nil. This is to prevent parts that have fallen off the map from continuing to fall forever.

  3. You can properly set Physics and Rendering Parameters for models, parts, and meshes in your experience to improve performace. Important properties include CanCollide, CanTouch, and CollisionFidelity. While they are more properties that impact performance, those are the most important regarding physics. If you want to learn more why those properties matter towards physics, click the links for the documentation reason why.

  4. For larger maps, it may be more suitable to use Instance Streaming to only show parts important to the player and not have them need to render some falling parts from across the map.

    In-experience instance streaming allows the Roblox engine to dynamically load and unload 3D content and related instances in regions of the world. This can improve the overall player experience in several ways.

Essentially what streaming does is only load parts of the in-game world to the player as opposed to the entire world leading to improved performance due to not needing to render as much. Note that this is typically for bigger maps since it does take time to load a new region and if a player fires a rocket into an unloaded region, it leads to some problems.

For more stuff about optimization I suggest you read Performance Optimization and Physic Computation Optimization which gives a very board overview on how to improve performance in your experience.

The steps I've listed above are very general but provide you good resources on how to improve physics performance without needing to go deeper into your experience to find the root cause such as using the MicroProfiler to find which physics step causes the most lag and which assembly is causing that lag or using the Developer Console to visualize which physics are being computed a lot.

I hope this explanation helps, if you want any questions or issues with my answer, feel free to comment it out and I'll edit my answer as needed or clarify in comments.

Sign up to request clarification or add additional context in comments.

2 Comments

Answer 1 is the only one that seems feasible because of a few main reasons. #2 does not work properly with the current system, but wouldn't be much of a help anyways, as many of the maps in the game have invisible barriers to prevent parts from leaving the boundary #3 was attempted, but didn't reduce lag and #4 is just bad design on our part, because the lobby for the game is 10k studs away from 0,0,0. This means that the game opening menu will not load because it cannot find the Camera1 in workspace (because technically, it doesn't exist) I will experiment and respond with results
Adaptive Timesteping definitely improved things! A structure that used to take around 2 minutes to fall is now falling in around 10-30 seconds!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.