Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I want to be able to destroy and deform a car in-game.

For example, I want two cars to crash and a) break the meshes apart (probably applying force to fly them apart) and b) deform the mesh (like bending the side doors).

How would I go about this?

Thank you in advance.

share|improve this question

3 Answers 3

I think the best way to deform your car would be with skeletal animation (see this sample and this one).

For example: have a "bone" (or two) for each door, the bonnet, the roof, the front, back, etc. And then you want to weight the vertices for that part of the car, to that bone, in an appropriate pattern (ie: some will have full weight, some might have partial weight). Then when your car gets hit - you move the bone for the section of the car that got hit inwards, towards the center.

It's not as nice as procedurally deforming the model. But it's a lot easier and your artist can then get things looking "just so". (And you can use the same system you might use for turning the wheels, etc.)

You probably also want to have two textures - a clean one and a dirty one. Then switch between the two in your pixel shader for different regions. This sample is probably a good place to start.

For breaking apart the model - I would suggest simply having different models for different parts. You could use the same bone structure so a car that breaks apart keeps the same damage deformation. (Or, alternately, have multiple root bones - one for the body, one for each door, etc, so they can be separated.)

For applying forces to make it fly apart (and getting nice matrices you can use to transform your parts) - you probably want to use a 3rd-party physics engine.

Finally: throw in a particle system for good measure.

This method should be pretty simple to implement for basic car damage in, say, a racing game. For something more severe, the same technique should still be viable - just with a lot more thought put into it.

The alternative is to rigging your model for damage is to do something procedural in your shader. This sample might be a good place to start - instead of shattering, you could move the vertices inwards depending on the direction of impact and their original position on the model. Although this is much harder - I wouldn't recommend it.

share|improve this answer

Most games fake this massively. They will break the car down into components (bumpers, doors, wings, bonnet, etc), and each component will have several versions, each for damage inflicted from different dimensions. With this approach it is also easy to break off parts, and have your doors animate like their hanging off hinges.

share|improve this answer

If you do not want to precompute or have artist created breakaways, I suggest getting or writing a physics engine that uses a Finite Element Method system. Examples of this are a video of a spaceship being deformed by asteroids and the physics in the commercial game The Force Unleashed, which both use DMM. I am uncertain when AMD will release their free DMM2 and Bullet physics package.

Also, I don't know how DMM2 interacts with XNA.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.