Download

Physics collisions are a joke to understand

Ok, I have a very simple goal here. Make a modular vehicle with an interior. Sounds easy right? Tons of games have customizable cars that a player can sit in, right?

So, let’s talk about the physics of this car. My understanding is that there are two types of collisions in the engine, primitives (shapes) and tri-mesh. Primitives are convex water-tight meshes, and tri-meshes are pretty much anything shape of geo you want. This difference in the engine is usually known as Simple Collision vs Complex Collision.

So let’s go back to our example, a car. Per the Unreal documentation, you should use a Skeletal Mesh to setup the body and the wheels. Ok, that’s fine. Let’s pull one into the editor and open up the Physics Asset.

Using one big collision primitive/shape could be useful for a car where nothing is going on inside of it. But we want a car with an interior (again, not a crazy request). So we do away with the one collision shape for the car. We can start setting up multiple collision shapes to kind of “carve out” the interior of the car. This becomes problematic for a few reasons though. First of all, it’s not really precise or easy to setup. Secondly, the more collision shapes you have, the more expensive they are (especially if they are moving). And a car, um, you know, needs to move to be useful. Hmm, ok, what about the tri-mesh option? If I wanted a “hole” in the collision where my modular door should be, tri-mesh should be able to do it without using multiple collision volumes. So tri-mesh to the rescue, right…?

Wrong! Custom tri-meshes (and you want a custom one, you don’t want a 20K vert collision tri-mesh coming from your final art) are only available on static meshes. Ok, so what now…?

Ok, crazy idea here: since a car is (for our purposes) a hard surface, why not use the car skeleton without the geo, then add a Static Mesh component to the Root bone and have a custom tri-mesh on that? We don’t need any weighted verts. Crazy thing is, this actually works. With one slight problem…

When you use a tri-mesh you can no longer simulate physics… so um, our car becomes useless again because it can’t move.

So a few things, no I can’t leave the car as one big primitive and disable collisions on the player when he enters the car. I need collisions in the interior of the car. And using a ton of different collision channels and swapping components to use the right one is a sound idea in theory but not really scalable and a nightmare in practice. And yes you could also have a custom movement component but then aren’t you reinventing the wheel (pun intended) here? All of these potential solutions sound hack-ish at best and flat out wrong at worst.

So, am I crazy (full disclosure: I probably am), or should there be a much simpler and straightforward way to do this…?

In other engines I’ve worked in, that’s pretty much always how it’s done.

You may have to build the car “manually” using physics join constraints between the different pieces. This is a lot more work than using the pre-canned vehicle support, but you also want to do things that the “typical game canned solution” isn’t really intended for.

FWIW, it’s a lot of fun to build a car out of static pieces, and put them together with joints, and then tweaking it all to get “monster truck” versus “econobox” versus “supercar” handling – you’re quite likely to need special physics hacks to make the supercar actually feel good. It just takes a lot of tweaking and patience!

Hmm, so to clarify: are you saying that you “build” the car using multiple collision primitives and not tri-mesh?

I believe you can use trimesh primitives for some of the shapes, but you want at least the wheels to be round (cylinders, ideally, although spheres, or even rays, have been used in the past.)
There’s also a question about how much of the linkage you want to simulate – is a wheel with steering just a sprung “up down” axis and a rotate-around-center axis, like a McPherson strut, or do you want double wishbone / A frame suspension? And so on.

Interesting. Whenever I use tri-mesh for collision on just a part of the “car”, physics on the entire actor seems to stop. Will investigate further, maybe I am missing something.

You may need to turn that “trimesh” into a set of convex pieces for the rigid body solver to work with it. You can do a reasonable job of this in the static mesh editor in the engine, do an automatic convex body decomposition.