Skip to end of metadata
Go to start of metadata

How do I damage my vehicle and not have it disappear?

Now that the player can ride about in his vehicle, we need to give him some incentive to get out again. Having the car explode when it's taking too much damage should do just fine.

 

Hierarchy and Naming Conventions

 

In order to have a vehicle explode properly, we first need to create a destroyed .cga of the vehicle we want to blow up. The destroyed version of your vehicle needs the suffix "_damaged" to its name("myVehicle.cga" and "myVehicle_damaged.cga").

Each part need to have a "_damaged" suffix as well (this includes the hull/body render node). Tires also need an extra "_rim" version, which is displayed when the player pops a tire.

Example: hierarchy for damaged meshes


Connecting to XML

We also need to add a couple of lines to our XML to make sure the vehicle explodes just the way we want it to. First of all, we need to tell the engine where to find the damaged version of the vehicle. We can define that in the <Animated> brackets in the "body" part.

 

 

  • "filename" was already defined, since that is the model we use for the live version of the car.
  • "filenameDestroyed" was kept empty before, since we couldn't destroy the vehicle anyway.

 

If the filepath and the names of the nodes in your DCC tool are correct, the engine will now switch to the "_damaged" versions of your parts once they are destroyed. Right under the <Physics> brackets, we also need to add the <Damages> brackets.


Adding a DamageGroup to our XML ensures that the vehicle can't be driven after it's been destroyed and that all passengers cease to be once the vehicle is destroyed.

Popping the Wheels

We also need to add components for the wheels and the body. Each parts component takes care of how many hitpoints a part has and what happens once a part takes too much damage. We'll start by adding a component for wheel1:


We also need to assign this component to the "wheel1" part, which is done in the part itself:


It makes sense to name the component uniquely, but similar to the name of the part it takes care of. Since "useBoundsFromParts" is set to 1, we don't need to set up a bounding box for the component, since it's just going to use the bounding box of the part it's assigned to.

The components damageBehavior "BlowTire" now takes care of switching the wheels model to its "_rim" variation if it takes too much damage. Once the vehicle explodes entirely, the wheel will be switched to its "_damaged" variation. Each wheel needs to have its own component, if you try to use a single component for more than one wheel, each of the wheels assigned to this component will be destroyed once any of them takes too much damage.

 

Step 1

 

 

Step 2

 

 

Step 3

 

 

 

  • No labels