Hi All, I am sorry, I just don’t know what I am doing wrong here. I have learn’t a lot while trying to find an answer, but nothing I have learn’t helps.
I have an empty game object, and to it, I have attached a script. In the start event of the script, I run a nested loop and create a wall of cubes 10x10, each cube has a rigid body attached and has a custom physics material with 0 bounciness. When the game runs, i would expect the wall to come tumbling down - and this is what it does BUT as the physics kick in… it becomes REALLY laggy.
Can someone please point me in the right direction here ?
There are a lot of things you can do to fix it:
Use fewer rigidbodies. It’s that simple, but a lot of the times you don’t have choice.
Avoid using mesh colliders and other complex colliders such as wheel colliders. Physx has to calculate collisions for each collider so the more you have the longer it will take. Mesh colliders and wheel colluders are the two most expensive to calculate so you should try to use cheaper colliders when you can.
Note: Physx probably does bounding volume checks to avoid calculating some collisions, but that won’t help you much in your case with a wall.
The physics time step is another very important piece that you need to work out. Found in the time manager, the physics time step determines how often the physics loop runs. Running it more frequently gives you more accuracy at the expense of performance. The higher you can set this number (hence making it run less frequently), the better. You can turn on interpolation in individual rigid bodies to help smooth out the jumps between physics loops for larger time steps.
In the Physics settings, the solver iteration count can also hurt performance. This factors into how many loops the physx does in calculating your collisions. Again, its more accurate the higher the number, but it will also slow down performance.
Run in a build. The editor gets poor performance because it has all sorts of things going on in the background while playing. Test your app in a build to get a better idea of how laggy it really is.