| Home Page | Recent Changes

Vehicles/TakeDamage

Don't kill the driver!

The TakeDamage can be changed so that if the vehicle is destroyed, the driver doesn't die, but takes a lot of damage. This is useful for smaller vehicles like bikes.

function TakeDamage(int Damage, Pawn instigatedBy, Vector hitlocation, 
                        Vector momentum, class<DamageType> damageType)
{
    Local Pawn OldDriver; //The driver that just exited

    // Avoid damage healing the car!
    if(Damage < 0)
        return;

    if(damageType == class'DamTypeSuperShockBeam')
        Health -= 100; // Instagib doesn't work on vehicles
    else
        Health -= 0.5 * Damage; // Weapons do less damage

    // The vehicle is dead!
    if(Health <= 0)
    {
        if ( Controller != None )
        {
            OldDriver = Driver;
            KDriverLeave(True); // Get the player out (forced)
            //Let the driver take a lot of damage
            OldDriver.TakeDamage(120, instigatedBy, hitlocation, momentum, damageType);
        }
        Destroy(); // Destroy the vehicle itself (see Destroyed)
    }
    KAddImpulse(momentum, hitlocation);
}

The Unreal Engine Documentation Site

Wiki Community

Topic Categories

Recent Changes

Offline Wiki

Unreal Engine

Console Commands

Terminology

FAQs

Help Desk

Mapping Topics

Mapping Lessons

UnrealEd Interface

UnrealScript Topics

UnrealScript Lessons

Making Mods

Class Tree

Modeling Topics

Chongqing Page

Log In