Weapons
182
This would be an excellent time to add more functionality to this, such as having the
mesh fracture into pieces. UDK offers a great tool for doing exactly this, although it's
beyond the scope of this recipe, so we'll pass over it for the moment.
We then trigger our sound effect and particle effect for the explosion. The current
particle effect is great, as it allows for a slow roasting flame along with smoke to
continue where the barrel was for quite some time after detonation. The spawning
of our physics mesh follows shortly after, and this kinetic actor is what allows the
barrel to be moved and manipulated within the world.
Finally, we call RespawnTime, which is actually defined in the default properties.
The barrel will respawn after a set number of seconds defined there.
- What good is an explosive barrel if it doesn't explode when hit? We need to create
a way for our barrel to explode when it takes damage, so the next function does
exactly that.
/****- Called when the object is shot or damaged
****/
simulated function TakeDamage
(int DamageAmount, Controller EventInstigator, vector
HitLocation, vector Momentum, classDamageType,
optional TraceHitInfo HitInfo, optional Actor DamageCauser)
{
if(!bDestroyed && bDestroyOnDmg)
{
Explode();
}
}
- Called when the object is shot or damaged
We check to see if our barrel is not destroyed and if it is to be destroyed when taking
damage. If both are true, call Explode()!
- That's not the only way to detonate our barrel though. We also have the option to
have it explode if it is touched, either by a vehicle or a pawn. Let's add that function:
/****- Called when a pawn/vehicle touches it
****/
simulated function Touch(Actor Other, PrimitiveComponent
OtherComp, vector HitLocation, vector HitNormal)
{
// Ignore if destroyed.
if(bDestroyed)
{
return;
}
- Called when a pawn/vehicle touches it