I’m working on a tactical RTS that uses a LOT of physics and colliders. Maybe that was a mistake, but I’m far too deep to turn back now lol.
I’m running into an issue where, beyond a certain number of characters (and therefore colliders), I get this rapid jittering effect on weapons and shields. The weapons and shields are all independent rigidbodies and colliders affixed to the characters’ skeletons with hinge joints and configurable joints.
Here’s a short video showing the jitter effect: https://youtu.be/7aLsr0cAHjQ
I’m guessing the issue is that there are so many colliders, close enough together, where the physics system is getting overwhelmed and is dropping pruning sweeps or otherwise reducing precision to cope.
Does that seem likely?
Is it possible its not collisions that are losing precision but enforcement of the bounds of the configurable joints and hinge joints?
What can I do to push the limits and be able to deploy more characters without this jitter effect?
Here’s some more details on what I have done so far:
- I’ve already doubled the Fixed Timestamp duration from 0.02s to 0.04s. I could probably push it longer but I only want to do that as a last resort.
- I’ve disabled collision between children of a character. That way collisions between a character’s own shield, spear, helmet, and hitboxes aren’t calculated. Here’s how I did that:
List<Collider> colliders = new List<Collider>(gameObject.GetComponents<Collider>());
colliders.AddRange(gameObject.GetComponentsInChildren<Collider>());
foreach (Collider c0 in colliders)
{
foreach (Collider c1 in colliders)
{
Physics.IgnoreCollision(c0, c1);
}
}
- I’ve altered the Layer Collision Matrix to restrict weapons to only collide with shields/armor and hitboxes. That way it shouldn’t be calculating collisions with the terrain (I’ve confirmed that all the objects/colliders are assigned to the right layer). Here’s a screenshot of my physics preferences: Imgur: The magic of the Internet
- As you can see above it’s set to Automatic Box Pruning for the Broadphase Type. I was originally using Sweep and Prune, which I think was performing slightly better, but it’s hard to say. I’ll probably switch back but maybe there’s an optimal option.
Has anyone done this sort of thing before where they use cartoonishly many colliders in relatively close proximity? If so please let me know if there are any optimizations or any low hanging fruit I should try. Any advice at all would be greatly appreciated.