| Home Page | Recent Changes | Preferences

MinigunAttachment

UT2003, Build 2225

class MinigunAttachment extends xWeaponAttachment; //Says the attachment is a weapon attachment

var class<MinigunMuzFlash3rd>     mMuzFlashClass; //Muzzle flash for the primary fire
var class<MinigunMuzAltFlash3rd>  mMuzAltFlashClass; //Muzzle flash for the secondary fire
var xEmitter            mMuzFlash3rd; //The emitter variable

var class<xEmitter>     mTracerClass; //Class of the tracer emitter
var xEmitter            mTracer; //The Tracer emitter itself
var float               mTracerFreq; /The frequency of tracers
var float               mTracerLen;
var float               mLastTracerTime;
var bool                mbGotHit;
var byte OldSpawnHitCount;
var vector              mTracerLoc; //Where the tracer hits
var rotator             mHitRot; 
var float               mTracerUpdateTime;

var float               mCurrentRoll;
var float               mRollInc;
var float               mRollUpdateTime;

var class<xEmitter>     mShellCaseEmitterClass;
var xEmitter            mShellCaseEmitter;
var() vector            mShellEmitterOffset;


function Destroyed()
{
    if (mTracer != None)
        mTracer.Destroy();

    if (mMuzFlash3rd != None)
        mMuzFlash3rd.Destroy();

    if (mShellCaseEmitter != None)
        mShellCaseEmitter.Destroy();

    Super.Destroyed();
}

simulated function UpdateRoll(float dt) //Updated the roll for the flash emitter attachment
{
    local rotator r;

    UpdateRollTime(false);

    if (mRollInc <= 0.f)
        return;

    mCurrentRoll += dt*mRollInc;
    mCurrentRoll = mCurrentRoll % 65536.f;
    r.Roll = int(mCurrentRoll);

    SetBoneRotation('Bone Barrels', r, 0, 1.f);
}

simulated function UpdateRollTime(bool bUpdate) 
{
    local float diff;

    diff = Level.TimeSeconds - mRollUpdateTime;

    if (bUpdate)
        mRollUpdateTime = Level.TimeSeconds;

    // TODO: clean up!
    if (diff > 0.2)
    {
        mbGotHit = false;
        mRollInc = 0.f;
    }
}

simulated function vector GetTracerStart() //Starts the tracer code
{
    local Pawn p;

    p = Pawn(Owner);

    if ( (p != None) && p.IsFirstPerson() && p.Weapon != None )
    {
        // 1st person
        return p.Weapon.GetEffectStart();
    }

    // 3rd person
    if ( mMuzFlash3rd != None )
        return mMuzFlash3rd.Location;
    else
        return Location;
}

simulated function UpdateTracer() //Updates the position for the tracer emitter
{
    local float len;
    local float invSpeed, hitDist;

    if (Level.NetMode == NM_DedicatedServer)
        return;

    if (mTracer == None)
    {
        mTracer = Spawn(mTracerClass);
        AttachToBone(mTracer, 'tip');
    }
    if ( Level.bDropDetail || Level.DetailMode == DM_Low )
        mTracerFreq = 2 * Default.mTracerFreq;
    else
        mTracerFreq = Default.mTracerFreq;

    if (mTracer != None && mbGotHit && 
        Level.TimeSeconds > mLastTracerTime + mTracerFreq)
    {
        mTracer.SetLocation(mTracerLoc);
        mTracer.SetRotation(mHitRot);

        hitDist = VSize(mHitLocation - mTracerLoc);

        len = mTracerLen * hitDist;
        invSpeed = 1.f / mTracer.mSpeedRange[1];

        mTracer.mLifeRange[0] = len * invSpeed;
        mTracer.mLifeRange[1] = mTracer.mLifeRange[0];
        mTracer.mSpawnVecB.Z = -1.f * (1.0-mTracerLen) * hitDist * invSpeed;
        mTracer.mStartParticles = 1;

        mLastTracerTime = Level.TimeSeconds;

        GotoState('TickTracer');
    }
}


function UpdateHit(Actor HitActor, vector HitLocation, vector HitNormal)
{
    SpawnHitCount++;
    mHitLocation = HitLocation;
    mHitActor = HitActor;
    mHitNormal = HitNormal;
}

simulated event ThirdPersonEffects() //What someone else sees of the emitters
{
    local rotator r;
    local class<MinigunMuzFlash3rd> muzClass;

    if ( (Level.NetMode == NM_DedicatedServer) || (Instigator == None) 
        || ((Level.TimeSeconds - LastRenderTime > 0.2) && (PlayerController(Instigator.Controller) == None)) )
        return;
    WeaponLight();

    if ( FlashCount > 0 )
    {
        if (FiringMode == 0)
        {
            muzClass = mMuzFlashClass;
            mTracerFreq = 0.11f;
            mRollInc = 65536.f*3.f;
        }
        else
        {
            muzClass = mMuzAltFlashClass;
            mTracerFreq = 0.33f;
            mRollInc = 65536.f;
        } 

        UpdateRollTime(true);
        mTracerLoc = GetTracerStart();
        
        mHitRot = rotator(mHitLocation - Instigator.Location);
        mTracerUpdateTime = Level.TimeSeconds;
        mbGotHit = true;
        UpdateTracer();
        if ( OldSpawnHitCount != SpawnHitCount )
        {
            OldSpawnHitCount = SpawnHitCount;
            GetHitInfo();
            if ( FiringMode == 0 )
                Spawn(class'HitEffect'.static.GetHitEffect(mHitActor, mHitLocation, mHitNormal),,, mHitLocation, Rotator(mHitNormal));
            else
                Spawn(class'XEffects.ExploWallHit',,, mHitLocation, Rotator(mHitNormal));
        }
        if (mMuzFlash3rd == None)
        {
            mMuzFlash3rd = Spawn(mMuzFlashClass);
            AttachToBone(mMuzFlash3rd, 'tip');
        }
        if (mMuzFlash3rd != None)
        {
            mMuzFlash3rd.Trigger(self, None);
            r.Roll = Rand(65536);
            SetBoneRotation('Bone Flash', r, 0, 1.f);
        }

        if ( (mShellCaseEmitter == None) && (Level.DetailMode != DM_Low) )
        {
            mShellCaseEmitter = Spawn(mShellCaseEmitterClass);
            if ( mShellCaseEmitter != None )
                AttachToBone(mShellCaseEmitter, 'shell');
        }
        if (mShellCaseEmitter != None)
            mShellCaseEmitter.mStartParticles++;
    }
    else
    {
        GotoState('');
    }

    Super.ThirdPersonEffects();
}

state TickTracer
{
    simulated function Tick(float deltaTime)
    {
        UpdateRoll(deltaTime);
    }
}

defaultproperties
{
     mMuzFlashClass=Class'XEffects.MinigunMuzFlash3rd'
     mMuzAltFlashClass=Class'XEffects.MinigunMuzAltFlash3rd'
     mTracerClass=Class'XEffects.Tracer'
     mTracerFreq=0.150000
     mTracerLen=0.800000
     mShellCaseEmitterClass=Class'XEffects.ShellSpewer' //The class of the shell emitter
     bHeavy=True
     bRapidFire=True
     bAltRapidFire=True
     LightType=LT_Pulse
     LightEffect=LE_NonIncidence
     LightBrightness=150.000000
     LightRadius=4.000000
     LightHue=30
     LightSaturation=150
     LightPeriod=3
     Mesh=SkeletalMesh'Weapons.Minigun_3rd' //Mesh of the weapon
}

Adding to this is always appreciated

Related Topics

Related Topics

MinigunAmmo

MinigunPickup

MinigunAmmoPickup

MinigunFire

InstantFire

Minigun

MinigunAttachment

Code References

Category Class (UT2003)

Comments

The Unreal Engine Documentation Site

Wiki Community

Topic Categories

Image Uploads

Random Page

Recent Changes

Offline Wiki

Unreal Engine

Console Commands

Terminology

Mapping Topics

Mapping Lessons

UnrealEd Interface

Questions&Answers

Scripting Topics

Scripting Lessons

Making Mods

Class Tree

Questions&Answers

Modeling Topics

Questions&Answers

Log In