Static vs. dynamic collision performance

Recently I’ve been figuring out collisions for my space stations and at first I was messing around with hull and box coliders which gave me shit performance for the accuracy I was getting no matter what I did.

Then I realised I could just make the station static-ish and give it a static mesh shape collider. For the hell of it I just threw the entire mesh at the engine to see it explode, but to my huge surprise the thing handled dead precise collision with no performance loss no matter how complex dynamic I collided with it.

It’s quite amazing how well it works, but it got me wondering how are then the dynamic collisions so many magnitudes worse in performance?

I mean as long as you are only colliding a dynamic against a static both appear to be able to move and rotate freely with no performance loss and I can’t really see why that wouldn’t work for all shapes.
But no, make a complex dynamic and everybody looses their minds!

Anyway, I’m interested in how this is handled in the background if any of you know and wouldn’t mind explaining or if you have any links to places that do have the info.
I guess I could just go read JBullet docs but I bet this is explained in a great way somewhere on da internetz and no harm in asking first, right?

P.S.
It works so well I can actually stick the front of a ship through the station trusses, attach a few modules so it’s stuck there and then plow space with it without any fps loss. :smile: All I haven’t been this pleased in months.

One of the distinction between a static and dynamic object that affects performance is that static object do not collide with another static object.

Eg. With 100 dynamic objects, there can be 4950 distinct collision pairs.
With 99 static objects and 1 dynamic, there can be only 99 distinct collision pairs.

What do you mean by this exactly? Do you mean a compound collision shape?

1 Like

That makes sense although even if you had just two objects in a scene, colliding two dynamics will be slower than one dynamic with one static I reckon.

For example, yes.

Then… your question is:
“Why is hitting one optimized mesh so much faster than hitting a dozen separate ones?”

Compound collision shapes are not really magic. You have to collide with all sides of every one of the subshapes.

Static objects do not move thus Bullet can optimize them. Eg. some calculations are done once and can be stored for a static object

That would make sense if you couldn’t move them. You can, and they work just as well as when not moving, which is exactly why this is so puzzling.

Hm. Actually more like: “Why is hitting one super heavy mesh so much faster than hitting a dozen ultra-optimised primitives?”

The super-heavy mesh has also been optimized for being static. It’s been spatially organized to provide fast local triangle collisions.

If you are moving it then it might be recalculating that… but static meshes should not move I guess. It’s odd that you are getting good behavior while it’s moving.

Well I hope the oddness persists :chimpanzee_smile:

No they don’t. If you’re moving mesh collision shapes its just working because you somehow trigger an edge case.

Moving a static mesh is like magically teleporting something into the scene, bullet probably detects the overlapping objects and the resolver pushes them apart. In effect you get some form of collision detection/overlap handling but no real physics simulation at all. I’d be suprised if you could realistically bounce objects off ‘teleporting’ static meshes.

@normen, @jmaasing here’s a video showing it. The station is the static collider and ships are dynamic compounds of almost 100 cubes (haven’t gotten to optimising yet).

I don’t know about you, but this is some super huge corner case.

Go to about 1:47 in the video. Surprise.

Oh and I reduced the station’s mass to about 1/4 of the normal one for demonstration, so it moves around quite a bit more.

That’s pretty nice and also, who cares if it is ‘correct’ physics or not, if it fits your game and does not introduce weird bugs - go for it, game development is all about fake it 'til you make it :slight_smile:

Well there is that one thing where if you crash into the station at very high speed the 1-2 front modules might clip inside it and the ship gets stuck. I’m fairly certain I can fix that in the collision listener or make you slow down for some reason.

Maybe a force field kind of shield that will slow but not stop objects.