[Phsyics] collider performance, gravity strength

Ok the scenario is I have a game with a pretty far away camera (imagine 2-3 times as high as the height of the highest tree on the map, almost strategy game like). Now I would love to go for some physics eye candy and at the moment I’m testing around with different colliders for my actors - especially cars, jeeps and tanks. How is the performance of the wheel collider, is it ok to put 4 wheel collliders and a capsule/box collider on every single vehicle when I will definitely have 20+ vehicles on screen (plus possibly some chunk flying around)?

As I said physics will be a pretty huge part of the gameplay experience, texture resolution etc will be lower than on a first person shooter as the camera is pretty far away. All I want is a quick estimate about how well wheel colliders perform compared to sphere/box colliders. I read that they use a raycast for their physics.

The second question would be that I have the feeling that a gravity of 9,81 is a bit low. A game object with the mass of 1000 and neither drag nor angular drag drops to the ground pretty slow with a very slow acceleration towards the ground (it accelerates pretty much like a feather, although it doesn’t have any drag). I would prefer keeping my numbers to real-life values (so a car should have a mass of 1-2k and behave accordingly) to keep things clear and understandable, so changing the gravity to something higher than in real life would be my best bet I guess?

With regards to the gravity, are you using 1 game scale as 1 meter? It seems to work for me if you assume this to be the case. Assuming the object is at rest, you can use this equation to determine where the object should be at different moments in time.

position = .5accelerationtime^2

They’re going to cost more than a box collider of course, as there is the tire simulation involved. They’re still relatively light as compared some of the more physically accurate models like the ‘advanced’ cars in the Unity example project.

There’s really no was to estimate how your 20+ cars will perform, as it depends on unknown factors like your target hardware, whether or not they’re all colliding with each other, etc. It’s not going to bring a modern machine to it’s knees I don’t think, just driving in a straight line.

Only one way to find out. Drop them into a scene and press play.

As far as mass and gravity, mass only comes into play during a collision. Mass does not affect the tire simulation, nor how fast an object falls. The scale of the mesh object however will affect how ‘heavy’ an object feels when it falls. Perhaps you have the mass correct, but the scale wrong on your objects.

Oh well thanks for the scale tip, my scale on the gameobject with the rigidbody attached to has been everything but realistic so that could be the issue - the model was just a child of that gameobject.

What’s a realistic number for the drag and angular drag for something like a car or jeep, assuming that I use 1 game scale = 1 meter and realistic scale/mass values? I cannot really see a real life equivalent to this setting other than the shape of an object, and it’s a bit hard to transfer the shape of an object into a float number. :slight_smile:

At the wheel collider: well ok as I don’t really see an alternative way to achieve a realistic car feeling in the movement of the object I might just go for it and throw in some tests as soon as my scene setup is farily finished.

As I’m typing this another question came to my mind. I limit the vehicle movement to x and z only while still maintaining the gravity - at the moment I’m achieving this with some code I wrote in the FixedUpdate routine after I calculated the new velocity, but if there is an option to limit all movement but gravity to 2 axes I would of course prefer that option as it might have better performance by some internal optimizations that just ignore one axis in all physics calculations. Is there something like that or is a custom approach the best bet at the moment?

Easy way to find out. Load up a Unity cube primitive and place it on top of your car in the scene.

There are no hard set rules, real world values don’t tend to give real world results. Pick some numbers that make sense, then tweak it iteratively until it looks and feels good.

The other option would be a configurable joint.

Still, if your camera is going to be high above the vehicles and you’re restricting the cars movement in such fashion perhaps scripting with translate or low friction rigidbodies sliding along the ground might be a better option for you. Who’s going to notice the wheel suspension from a few hundred feet up? Fake it all.

I’m a little confused I guess. You started off talking about realistic values and numbers, then in the next breath want to lock it to the ground and not let the car so much as jump over a speed bump with any discernible deflection?

Sorry I think I explained the y limitation wrong. I don’t hard limit the y movement, only the vehicle acceleration should be limited to 2 dimensions. At the moment it is like that: if a waypoint is below the height of the car, the car has a velocity towards the waypoint with a included y component. In real life that doesn’t make any sense as the only thing that causes your car to move down a hill is gravity, you can only accelerate straight forward. So what I currently do is calculate a relative acceleration limited to the local x and z axis of the vehicle, that’s the force caused by the engine of the vehicle so to speak. If the vehicle enters falling terrain, the gravity causes it to drop down and rotate parallel to the terrain like in real life. the engine acceleration however is relative to the car still limited to 2 axes.

My aim is to implement a way to create the local engine force as performance optimized as possible without creating a lot of garbage by creating multiple vector3 instances every frame.

EDIT: I tried using a box or capsule collider only for the vehicles, but as soon as they drive over rough terrain the physics just suck. The wheel colliders provide a pretty nice behaviour no matter where my vehicles are driving. I think I will just go for wheel colliders and start some heavier tests on my target hardware as soon as possible.

The simple solution would be to zero out the Y component of the vector when you assign the position of the waypoint to follow.

Just a quick update. I actually made it by centering out the velocity caused by the car to 2 angles while maintaining the physics (gravity, explosions) forces. It works pretty good, gravity works perfectly fine now with the right settings (my tests brought me to the conclusion that air drag is almost 0 for cars, it really feels best without it or with a very low value, angular drag is also <1 at my setup.

I even got a box collider set up exactly as I wanted it to be, so no need for the wheel colliders! When I first tried the box collider I got some issues on uneven ground as I said before, but now I figured out that the physics engine obviously takes the center of the gameobject the collider is attached to as the center of weight of the object. That sure makes a lot of sense, so I just put the center of the gameobejct pretty much to the bottom of the box collider and now I don’t have any problems with uneven terrain and the vehicles move pretty solid. For my camera perspective there’s no need for wheel colliders, looks like faking is my best friend here. :slight_smile:

Thanks for the great responses, I think I found the perfect solution for my needs for both visual feeling and performance.