Lets Have It Blow Up

Overview

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.

This is the hierarchy for the attached .CGAs:

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.

<Animated filename="objects/vehicles/default_vehicles/simple_4_wheels_destroyable.cga" filenameDestroyed="objects/vehicles/default_vehicles/simple_4_wheels_destroyable_damaged.cga"/>
  • "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.

<Damages submergedRatioMax="1" submergedDamageMult="1" groundCollisionMinMult="1.3" groundCollisionMaxMult="1.4" groundCollisionMinSpeed="8" groundCollisionMaxSpeed="22" vehicleCollisionDestructionSpeed="18" aiKillPlayerSpeed="7" playerKillAISpeed="7" aiKillAISpeed="7">
        <DamagesGroups>
            <DamagesGroup name="Destroy" useTemplate="CarDestroy"/>
        </DamagesGroups>
</Damages>

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 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:

  <Component name="cWheel1" damageMax="100" major="1" useBoundsFromParts="1" hullAffection="0">
  <DamageBehaviors>
    <DamageBehavior class="BlowTire" damageRatioMin="1">
      <BlowTire />
    </DamageBehavior>
  </DamageBehaviors>
  </Component>

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

<Part name="wheel1" [...] component="cWheel1">

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.

Blowing up the entire car

Destroying the entire car is similar to destroying a tire, we'll start by adding a component for the body.

<Component name="cBody" damageMax="1000" useBoundsFromParts="1">
  <DamageBehaviors>
    <DamageBehavior class="Group" damageRatioMin="1">
      <Group name="Destroy"/>
    </DamageBehavior>
  </DamageBehaviors>
</Component>

We'll assign that to the appropriate part as well:

<Part name="body"[...]component="cBody">

The component is fairly similar to the one we added for the wheels, it's also using the bounding box of the part it's assigned to and it calls for a certain damageBehavior once it took too much damage.

The main difference between this component and the wheel components is the damageBehavior that's assigned to it. We're using the "Destroy" group we defined earlier in the <Damages> brackets, which will switch the entire asset to the "_damaged" variation, kill all passengers and makes the vehicle unusable.

Adding some flair

It looks like everything is working from a technical point of view, but I feel we're lacking a bit of flamboyance.

Let's add an explosion! First of all, we need to find a suitable particle effect and add it to our vehicle.

<Particles>
  <DamageEffects>
    <DamageEffect name="VehicleDestroyed" effect="Crysis3_veh_assault_buggy.damage.explosion" scaleMax="1.5" gravityDirection="0,0,1"/>
  </DamageEffects>
</Particles>

Just add the <Particles> brackets somewhere in between the <Vehicle> brackets in your XML, but make sure it's outside of any of the other brackets, like <Parts> or <Components>.

The name of the damageEffect should be unique and, in the best case, hint towards the kind of particle to expect, we're gonna use this particle when the vehicle is destroyed, so "VehicleDestroyed" seems like an reasonable name.

Now we need to make sure the effect gets triggered, when the vehicle explodes.For this we only need to add another DamageBehavior to our "cBody" component.

<Component name="cBody" damageMax="1000" useBoundsFromParts="1">
  <DamageBehaviors>
                  [...]
    <DamageBehavior class="Effect">
      <Effect effect="VehicleDestroyed"/>
    </DamageBehavior>
  </DamageBehaviors>
</Component>

The DamageBehavior "Effect" simply displays the particle effect you define in the "effect" property once the part is destroyed.

There are plenty of ways to tweak the destruction of a vehicle and you can go into great detail making each explosion your own, but this basic setup should be enough to make sure the vehicle behaves properly for now.

|| Adding a weakspot>>