- Home /
Physics optimization
Hi! I used Profiler to find reason of low FPS in my game. And I seen that about 90-99% of CPU Usage is in Physics (in some moments).
Some more statistics: - Active Rigidbodies: 870-930 - Sleep Rigidbodies (Sleep Velocity - 0.15): about 30 - Number of contacts: about 3K - Static Colliders: about 200 - Dynamic Colliders: about 1K
I know that there're a lot of rigidbodies and a lot of collisions in this game, but I can't remove any rigidbody or subtract the number of collisions. I use ONLY Box Colliders, there aren't any mesh colliders in my game.
I hope you can help me...
I'm not sure what help anyone can give... you've already observed that physics calculations is your biggest bottleneck, yet you've also said that you can't remove any rigidbodies or subtract the number of collisions. So you've got little alternative but to accept the inevitably low frame rate.
Answer by Nabeel Saleem · Jun 26, 2014 at 07:46 PM
Do some changes in timstep goto edit > project settings > time
Set Fixed TimeStep to 0.01 in Time Manager.
and also change solver iteration count from 7 to 1 in physics setting. /
check your objects delete non-sleeping rigid bodies if they don't needed.
Setting FixedTimeStep makes some negative changes in my game :(
Because you went the wrong direction. Set it to .05 and see how it does
@Team_26 do some more changes in time and physics you will get good result. make your objects in uniform scale
If I change it from 0.02 to 0.025 there're much no-realistic behaviours of my objects...
0.01 (100 physics frame get calculated for a single second) for fixed timestep is ridiculously high especially if you are targetting mobile devices. I get a pretty good result with 0.033 (30 physics frames get calculated for a single second).
And changing iteration counts from 7 to 1 will probably give you a pretty inaccurate physic result.
Answer by screenname_taken · Jun 26, 2014 at 07:16 PM
Do you need all those rigidbodies active all the time? I mean you have them in the screen affecting the player?
Did you try tweaking the collision layers and the solver iteration counter?
Answer by Kiwasi · Jun 26, 2014 at 07:51 PM
Without knowing the details of your game I'm not sure if this will work, but in some cases combining multiple box colliders into a single mesh collider can be more effective. This is how Mine Craft works. It doesn't have thousands of cubes with colliders, it has a single mesh collider that gets updated every time a cube is moved.
I found this tutorial really useful. Again, not sure if the technique is valid for your game. Try the other solutions as well.
Thank you. I think it isn't good for this game (because some box are in other position and rotate and in some moments they aren't colliding), but it can be useful in future.