Even though i programmed a more or less simple game
it lags really a lot. Using the profiler i found out that the Physics take up nearly 95% of total CPU usage.
And 1 specif process called PhysX.Sc::Scene::postIslandGen takes up 85-90% of total CPU usage. What is that procces and how can i make it use less CPU?
The most often cause that I see has nothing to do with physics in fact. As you know, we’re running physics on a fixed frequency, and that means should a heavy graphics or logical frame occur we have to catch up on that big delta by calling the physics simulation a couple more extra times per frame. You might be able to see that right before the peak Physics.Processing was called 1 or 2 times whereas during the peak it’s being called around 10 or so.
If not, this must have something to do with what’s inside your physics scene (performance might be dropped for different reasons this case, that would have to do with the amount of contacts in your scene).
I’m a little late, but I’ve been running into this problem with one of the scenes in a game I’m working on (as the coder, it’s my job to optimize level designer’s work I guess haha). The problem in this particular scene was a number of mesh colliders that had their negative performance impact GREATLY increased by the AI navigating over them via a nav mesh (it was some rubble, and navigable building exteriors that weren’t set up with proper compound colliders).
In your case you say that you don’t have any mesh colliders (other than the terrain which is fine), so there are a couple of things to look at. First, make sure those sphere triggers have rigidbodies. Any collider without a rigidbody that gets moved via transform ends up being a huge performance issue. Second, maybe just get rid of the sphere colliders on everything you can. Having that many colliders pop into and out of existence with all their physics interaction is going to have a huge performance overhead. You may be better off doing raycasts for line of sight, and just Lerping a visual effect from the tower to the enemy without any triggers. You could reserve colliders for towers that should miss once in a while like cannons or rockets (although these could definitely have the physics optimized out of them as well if that turns into a problem).
Basic rule of thumb: Anything with a lot of bullets and things of that nature still needs to have the physics faked as much as possible with modern technology.