dim3 Forum

Full Version: Bleeding enemies
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Tutorial: Bleeding enemies

A lot of games indicate the death of an enemy by showing a puddle of blood under his body.

[Image: 20080404140444ko9.png]
Yep. He's dead. Didn't look alive to begin with, though.

In this tutorial, I will explain how to do just that, so let's begin right away.

Step 1: Create a blood puddle/splatter image.
This is simple. Just create the image you want to show when the enemy is dead.
I'm using this one: http://img89.imageshack.us/img89/9000/splattertt6.png
Make sure to leave the background transparent, or you will end up with a white square under your model.
Copy the image to Data/Bitmaps/Marks/.

Step 2: Edit the marks.xml
Open Data/Settings/Marks.xml in your text editor and create a new mark for your blood image.
I use these settings:
Code:
    <Mark name="splatter">
        <Setting time="100000" fade_in="1" fade_out="50" no_rotate="false" />

        <Image file="splatter" count="1" time="200" loop="true" />

    </Mark>
You will want to change the name and fade times though, depending on the effect you want to create.

Step 3: Add a bone to your model
Another simple step. Add a bone to spawn the blood from to your model.
Like this for example: http://img245.imageshack.us/img245/8175/bild14pu1.png
Make sure it's placed outside of the model but above the ground during your death animation.

Step 4: Create the projectile script
Now you need a projectile to be spawned that leaves the blood mark.
I use a modified version of the bullet script that comes with the Dim3 Demo.
It looks like this:
Code:
// ***********************************************************
//
// PROJECTILE: Blood
//
// ***********************************************************
//
// blood construction
//
function bloodConstruct(proj)
{
        // hit scan type projectile
    proj.setting.hitScan=true;
    
        // speed
    proj.speed.maxHitScanDistance=150000;

    proj.action.damage=0; //no damage
    proj.action.collision=true;

        // decal (for hitting map) <-- this is the important part :)
    proj.mark.on=true;
    proj.mark.name="splatter"; //the name of your mark
    proj.mark.size=2000;
    proj.mark.alpha=1;
}

//
// blood hit
//

function bloodHit(proj)
{
    proj.action.destroy();
}

//
// events
//

function event(proj,mainEvent,subEvent,eventId,tick)
{
    switch (mainEvent) {
        case DIM3_EVENT_CONSTRUCT:
            bloodConstruct(proj);
            return;        
        case DIM3_EVENT_HIT:
            bloodHit(proj);
            return;
    }
}

Step 5: Setting up a weapon script that fires the projectile
Now you set up a weapon script that shoots the blood projectile. I use a modified JoeFoe Fireball weapon:
Code:
// ***********************************************************
//
// WEAPON: BLOOD
//
// ***********************************************************


//
// blood weapon construction
//

function bloodWeaponConstruct(weap)

{

        // projectile setup

    weap.projectile.objectFireBoneTag='splt'; //name of your "blood bone"
    weap.projectile.objectFirePoseName='Hithard'; //the death animation

        // the projectile

    weap.projectile.add('blood'); //the name of your blood projectile
}

//
// blood spawn
//

function bloodWeaponFire(weap,subEvent,tick)
{
        // spawn projectiles
    // This functions spawns three blood splatter projectiles at a -90° x angle and at random Y and Z angles.
    // Depending on the effect you want to create, one image could be enough. You will also have to use different
    // angle values, depending on your animation.

    weap.projectile.spawnFromObjectBoneOffsetAngle('blood',-90,utility.random.getInteger(-20,20),utility.random.getInteger(-20,20));
    weap.projectile.spawnFromObjectBoneOffsetAngle('blood',-90,utility.random.getInteger(-20,20),utility.random.getInteger(-20,20));
    weap.projectile.spawnFromObjectBoneOffsetAngle('blood',-90,utility.random.getInteger(-20,20),utility.random.getInteger(-20,20));
}

//
// events
//

function event(weap,mainEvent,subEvent,id,tick)
{
    switch (mainEvent) {
        case DIM3_EVENT_CONSTRUCT:
            bloodWeaponConstruct(weap);
            return;
        case DIM3_EVENT_WEAPON_FIRE:
            bloodWeaponFire(weap,subEvent,tick);
            return;
    }
}

Step 6: Firing the projectile from the enemy script
Now you will have to adjust your enemy script to actually spawn the projectile.
First, add your blood weapon. (In the construct.)
Code:
obj.weapon.add('blood');
Now in the death function of your enemy, add
Code:
obj.weapon.fire('blood');

Step 7: Test it!
Everything should work now. If it doesn't, experiment with the different values a little or post about it on the forum.


EDIT: Of course you may not use my blood splatter image. Smile
Reference URL's