Search Unity

(Havok) Best performance for large scale, simple physics using physics bodies

Discussion in 'Physics for ECS' started by BigRookGames, Dec 10, 2020.

  1. BigRookGames

    BigRookGames

    Joined:
    Nov 24, 2014
    Posts:
    330
    I am trying to find out the best way to simulate physics using a large number of pathfinding agents (roughly 5000). I have been tweaking the settings on the physics body component and messing around with other settings, but am curious if there are any suggestions on setup when doing this.

    I assume the engine is much more optimized than I would be able to quickly script for such a use case, so am trying to avoid doing so.

    the physics doesn't have to be very precise because the agents are very hectic in their motion and in-accuracies likely wouldn't be noticed. I would even go as far as saying a simple capsule overlap positional adjustment would be okay.

    I am currently using these settings:
    the motion type on the bodies to Dynamic, no smoothing. Also, they are using gravity.
    for the Physics Shape, I am using a box collider with the bevel radius maxed (I assumed this was more efficient than a strict box, as the sides could use point distance checks to determine overlap, but I may be wrong.)
    I have the collision response on Collide. Friction at .5 and restitution at 0.

    Are there any settings that would drastically improve the performance of the physics engine? If compromising collision check quality, that is okay! like I said it isn't super important, less so than the number of units.

    Also, not sure if the engine already does this, but with so many units I was considering implementing a LOD-type precision system where further away units update less frequently and at a lower solver iteration or even drop the physics altogether and just run local avoidance calculations, but haven't tried implementing a system like that yet. Another idea that came to mind is using very simple sphere checks for a collision at a certain distance, and within a certain area from the player, a slightly more complex collider be used.

    Anyway, I would love to hear anything about what would make the current physics shape and body most efficient.

     
    Last edited: Dec 11, 2020
  2. petarmHavok

    petarmHavok

    Joined:
    Nov 20, 2018
    Posts:
    461
    Well there are certainly better shapes for collision performance than box, both for collision detection and solving. Try capsules or even spheres if possible.

    Also, you can freeze some of the rotation with inertia, so that for example capsule never tips over and similar.
     
    BigRookGames likes this.
  3. steveeHavok

    steveeHavok

    Joined:
    Mar 19, 2019
    Posts:
    481
    Do you need the full collision detection and resolution at all? Are you really only looking overlap information? If you have everything as sphere and set their CollisionResponse to RaiseTriggerEvents you could plow through the overlaps yourself maybe applying your own simple local steering avoidance impulses, rather than full collision resolution.
     
    NotaNaN and BigRookGames like this.
  4. BigRookGames

    BigRookGames

    Joined:
    Nov 24, 2014
    Posts:
    330
    Yes, that would be better I think. I am running my own rvo based steering behavior but with the number of agents, they overlap in groups.

    I may try to do what you mentioned, though I have been working on it a few days and have been able to get it pretty efficient overall, getting a couple thousand units on top of each other without much cost, and that is with box colliders.

    I will update here if I implement what you suggested.

    Thanks for the info.
     
    steveeHavok and petarmHavok like this.
  5. BigRookGames

    BigRookGames

    Joined:
    Nov 24, 2014
    Posts:
    330
    I've gone through the code and made a lot of changes after re-reading the optimization suggestions for burst and ecs in general, and I've found that the performance has become much better. Now with a few thousand agents, the physics calculations only run about 0.2ms and the movement (pathfinding, ground hover, rvo/flocking) runs really nice around 1ms total.

     
    steveeHavok and petarmHavok like this.
  6. petarmHavok

    petarmHavok

    Joined:
    Nov 20, 2018
    Posts:
    461
    Love it!
     
    BigRookGames likes this.