So i have been working on a game for several months now (current progress can be seen here).
Currently the game is working exceptionally well, so long as I don’t have more than about 8 cars in the world. This is a problem as I’d like to have at least 16, if not more.
The problem cropped up early on when I realized the default ray-vehicle in jbullet didn’t support wheel collisions. RC Car’s all have big wheels and this is a must, so I figured it was worth it to just write my own from scratch. It’s constraint based and relies on 1 physics rigid body per wheel to collide and do most the computations. By themselves these are fairly fast but obviously with 4 phys objects per car + the car body = 5 * 8 cars = 40 phys objects all wanting to smash into eachother things start to slow down. at 16 cars that’s 80 phys objects and my hefty i7 doesn’t want to get close, let alone anyone with an older computer.
So I’m in a bind, my current system can probably run ok but I’d have to limit race size and the tracks I plan on making would have to go with fewer dynamic physics objects themselves (no windmills I guess) which anyone who’s played games like Re-Volt will remember the dynamic world objects were lots of fun. (beach balls, trains and pianos!)
I’ve thought about trying the following:
1: Phys Layers, divy up the cars to each have their own phys layer for traction & environment collisions and put them all on a different layer for inter-car collision. Layers are limited so I wouldn’t be hitting my goal. Would this offer any sort of performance increase? (something tells me no )
2: Multi-phys spaces, This one sounds like a pain in the :oops: but I’m not convinced it would be impossible. Unless I’m blatantly wrong in that regard does anyone have any ideas if this could work and maybe point me in the right direction? it would probably be similar to the above method with each car having a phys space for environment collisions, and a seperate phys space for the inter-car collisions.
3: lastly, my method sucks. I can freely admit I might have really just messed up conceptually here, and if anyone has any suggestions on a different way to handle car on car collisions with wheels that could be twice as large as the body of the vehicle (exaggeration but you get the point) I’m all ears. I have already attempted to modify the existing ray car to position objects in a compound collision shape to get accurate wheel collision but it either messed with the ray-car’s casting or the actual collisions just weren’t right (no suspension interaction, stiff collisions, collisions which just weren’t physically possible )
For more in detail on my cars:
I have 1 regular rigid body which has 4 slider joints I extended to support spring mechanics. Attached to the opposite end of each slider is 1 custom rigid body with a capsule object which has a physics listener to determine collisions and process the traction algorithms. Capsule instead of cylinder to prevent some annoying clipping issues. (gives goods results but still work in progress) The wheels don’t actually spin, but slide across the ground!
For those curious about my performance characteristics:
I have run several tests with 1, 5 and 10 cars to determine where my performance is going. Between 70-98% of the cpu is going into broadphase, increasing with the count of cars (obviously) this is all prior to serious graphics enhancements and any ai to speak of (which will of course want some cpu as well). (i-7 8 3.1ghz, 8g ram, 560ti sli)
Apologeez in advance if this is the wrong forum, I figured it was similar to troubleshooting or could benefit someone in the future.