r/howdidtheycodeit • • Sep 01 '22
Question how do games do car crashes?
Many car games or even games that have cars like GTA have cars that bend wherever they crash into something, or the windshield breaks when hit by something or the roof bends if something falls on the car.
How does something like this work?
20
Upvotes
25
u/Putnam3145 IndieDev Sep 01 '22
The general term for this is soft body dynamics. I don't know anything specific about it, but I hope having a keyword to search will help you.
BeamNG.drive's website goes over their own implementation in some detail.
It should also be noted that it's fully possible that they just swap out "pristine" models for "damaged" models as the cars take more and more damage. I think this is what earlier (PS2-era) GTA games did, even.
13
u/Dave-Face Sep 01 '22
It is a combination of several effects, with a lot of artistic direction. Is is rarely (if ever, besides BeamNG.drive) actually soft body physics - that isn’t necessary for most games, and is quite difficult / expensive (performance) to render.
A cracked windscreen is just a material effect, triggered when the front of the car is damaged. The car body will have multiple vertex deformations store which goes from intact to damaged, with some material effects on top e.g crumpled metal. If a hit is detected the relevant deformations are increased to show the damage. Bits falling off are simply detecting a health threshold of some king and spawning a bit of the original mesh as it’s own thing.
7
u/rean2 Sep 01 '22
A mesh is just a series of points, line, and face data.
You can modify meshes via code by modifying this data. So on a car collision impact, it's basically finding the points close to the collision, offsetting them, then updating the renderer with the new modified mesh.