We all know that WheelCollider is the more expensive collider to process, especially on iPhone.
Let’s suppose we have some cars with 4 WheelColliders and 2 BoxColliders for the overall shape each, and some simple code to make them move: while on PC and big consoles you can easily have more than 20 cars running togheter at 60 FPS, on iPhone you can’t have more than 6 cars without dropping under 30 FPS.
Six cars on screen could be enough to have some fun, but what if I want to play with more?
I guess the cheapest way to do it is having an unique BoxCollider for the whole car. Or, if we want to get it more precise, we could use 4 additional SphereColliders placed on the wheels.
I have been trying both ways for some time, but I never succeded. To be honest, the best result I obtained was having a car wich looked like it was sliding on ice… Also, the car wasn’t even able to climb the slightest ramps.
Since I wanted to mantain the physical simulation, I always relied on rigidbody.addRelativeForce and rigidbody.addRelativeTorque to get the vehicle moving and rotating, but as I said, this led it to slide around without much control.
And probably, it’s only my lack of serious knowledge about physics…
So, did any of you ever tried to do something similar? Do you have some example code you may want to post to explain this and get started? Every help is really greatly accepted. Thanks!
Ok… Even if I didn’t succeded to build a non-WheelCollider vehicle, I have just finished some test runs… And results are great!
This is my configuration: - iPod Touch 4 - 10 cars on screen (including the player’s one) with 4 WheelColliders, 1 BoxCollider and 1 CapsuleCollider each - Camera scripts that change visuals dinamically depending on inclination and steering (many calculations are involved) - One OnGUI draw call - No pixel lights - No antialias - No VBL Sync - More than 17.000 triangles on screen - Accidents and crashes everywhere
Result: iPod is sticked to 29-30 FPS in every situation.
Ok, maybe it’s nothing new for you experts, but I think it’s a good result, considering that there are 40 WheelColliders around the scene… I guess everything will run quite smooth with 8 cars, a standard surrounding scenario and some basic AI calculations.
Anyway, I noticed that FPS are limited to 30 FPS, they never reach higher values. Is it possible to unlock them?
iOS has a defined FPS that you can set in AppController.mm in Xcode. Set #define kFPS to the value you want. The maximum screen refresh rate is 60 FPS, so no point going higher. And I believe any lower value should be a result of 60 divided by an integer, so 30, 20, 15, etc.
Very well… I changed #define kFPS from 30 to 60, and now I always register from 30 to 60 FPS with 12 cars. This is insane… O_o
Then, just to stress a bit more this sweet ARM Cortex-A8, I put in the scenery a total of 16 cars: now framerate varied from 20 to 59 depending on how much traffic was going on the sceen, with an average of 30 FPS. The console also shown a peak of 28.703 triangles and 15.843 vertices. Ok, it’s starting to get quite chaotic, but I’m impressed by this results.
I guess there’s no more need to build a non-WheelCollider car.