How to stop lag with a lot of rigid bodies.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Jai

I am trying to create a 3D game where you shoot a gun to knock down block towers. As each level has around 150 individual rigid bodies with sprites and collision shapes, it causes a lot of lag. Is there anyway to either limit the amount of rigid bodies while still making blocks stack as towers, or to limit the lag in general. I am also using the directional light node to accurately display sunlight, which probably isn’t helping, but I don’t know of another way to make artificial lighting.

:bust_in_silhouette: Reply From: CassanovaWong

Hmmm, maybe sharing some of the code would help me identify… there are lots of debug plugins no, maybe could help identify… personally had a lot of trouble using physics process calls with many units… and especially area2D… With Rigid Bodies, many times it’s in the code structure… as in, using Physics process or process when the call should be mad in the intergrate forces… There are several waysto minimize instances in a scene or at least to limit the frequency they are made per framerate, … for instance since there are about 60 frames per second, and the human eye can only catch about 27 of them… making calls every other frame may help, or instead of instancing each individual body, you can duplicate them, recycle them or just use a visual reference. Of them… and oh oh oh, biggies is set visibility… haven’t worked with it much in 4 and looks like it’s been changed up a bit

I don’t have any code for the Rigid Bodies, as I just have them on the same collision layer as the tennis ball (it’s a g rated game so it’s a tennis ball launcher rather than a gun). I can share the entire project if that helps, but it is very laggy even after turning shadows off. If there is any solution I would love to know.

Jai | 2023-04-05 00:28

Well, yeah, I think I’d have to see the code to be of any help… have you used debugging tools of any kind? there’s some good plugins for godot on github… try a search. it may help. at least to pinpoint the trouble…

CassanovaWong | 2023-04-08 08:57