UnrealScript Game Programming Cookbook

(Chris Devlin) #1
Chapter 6

181

}


//Generate fire particle after object destruction
if(ParticlesOnDestroy != None)
{
PSC = WorldInfo.MyEmitterPool.SpawnEmitter
(ParticlesOnDestroy, Location, Rotation);
}


// Spawn physics mesh
if(SpawnPhysMesh != None)
{
PhysMesh = spawn(class'UTSD_SpawnedKActor',,,Location,
Rotation);
PhysMesh.StaticMeshComponent.SetStaticMesh
(SpawnPhysMesh);
PhysMesh.StaticMeshComponent.SetRBLinearVelocity
(SpawnPhysMeshLinearVel, FALSE);
PhysMesh.StaticMeshComponent.SetRBAngularVelocity
(SpawnPhysMeshAngVel, FALSE);
PhysMesh.StaticMeshComponent.WakeRigidBody();


// Collides with the world but, not players or vehicles
PhysMesh.SetCollision(FALSE, FALSE);
PhysMesh.StaticMeshComponent.SetRBChannel
(RBCC_Default);
PhysMesh.StaticMeshComponent.SetRBCollidesWithChannel
(RBCC_Default, TRUE);


// Set lifespan
PhysMesh.LifeSpan = SpawnPhysMeshLifeSpan;
}
bDestroyed = TRUE;
TimeToRespawn = RespawnTime;


// It will respawn after (X) seconds
SetTimer(RespawnTime, FALSE, 'RespawnDestructible');
}


Next, if our static mesh is destroyed, we need to either hide it, or replace it with a
destroyed version of our mesh. This is particularly useful when dealing with larger
objects, such as vehicles. When a vehicle explodes surely there must be something
left behind, right? Because we are using a static mesh natively supplied from UDK,
we don't have a replacement mesh. We simply tell the mesh to disappear.

Free download pdf