so lets look at the code:
Code:
simulated function PostBeginPlay() { local Rotator R; local PlayerController PC; if ( !PhysicsVolume.bWaterVolume && (Level.NetMode != NM_DedicatedServer) ) { PC = Level.GetLocalPlayerController(); if ( (PC.ViewTarget != None) && VSize(PC.ViewTarget.Location - Location) < 6000 ) Trail = Spawn(class'FlakShellTrail',self); Glow = Spawn(class'FlakGlow', self); } Super.PostBeginPlay(); Velocity = Vector(Rotation) * Speed; R = Rotation; R.Roll = 32768; SetRotation(R); Velocity.z += TossZ; initialDir = Velocity; }
In this particular case, right after the object is finsihed spawning, it spawns a trail emmiter, a glow effect, and gives itself a intiial direction and velocity (since the object had PHYS_Falling as is determined by the defualt proprties, UT will automaitically apply gravity to it in the effect of negative z velocity....)
Next:
Code:
simulated function destroyed() { if ( Trail != None ) Trail.mRegen=False; if ( glow != None ) Glow.Destroy(); Super.Destroyed(); }
Code:
simulated function ProcessTouch(Actor Other, Vector HitLocation) { if ( Other != Instigator ) { SpawnEffects(HitLocation, -1 * Normal(Velocity) ); Explode(HitLocation,Normal(HitLocation-Other.Location)); } } simulated function Landed( vector HitNormal ) { SpawnEffects( Location, HitNormal ); Explode(Location,HitNormal); } simulated function HitWall (vector HitNormal, actor Wall) { Landed(HitNormal); }
Uscript is not as efficiant as native code, thus a lot of it is event driven. You try to write code that spends most of it's time waiting for the engine to pass an event to it. In the case of projectiles, there are three functions that might be called on collison with another obeject:
ProccessTouch, called when an actor colides with another actor
Landed, called when the actor hits a mostly horzontal pice of geometry
HitWall, called when it hits a mostly vertical pice of geometry (or a static mesh)
This is so you don't have to keep cheching in code every tick if the projectile collided with something. (wchi is very inefficient)
So anhow the above says, "If I hit something, SpawnEffects (calles the SpawnEffects Funciton), and Explode (call the explode funciton)"
The above two funcitons could have been merged, I think they sperated them to keep the code alittle cleaner...
Code:
simulated function SpawnEffects( vector HitLocation, vector HitNormal ) { local PlayerController PC; PlaySound (Sound'WeaponSounds.BExplosion1',,3*TransientSoundVolume); if ( EffectIsRelevant(Location,false) ) { PC = Level.GetLocalPlayerController(); if ( (PC.ViewTarget != None) && VSize(PC.ViewTarget.Location - Location) < 3000 ) spawn(class'FlakExplosion',,,HitLocation + HitNormal*16 ); spawn(class'FlashExplosion',,,HitLocation + HitNormal*16 ); spawn(class'RocketSmokeRing',,,HitLocation + HitNormal*16, rotator(HitNormal) ); if ( (ExplosionDecal != None) && (Level.NetMode != NM_DedicatedServer) ) Spawn(ExplosionDecal,self,,HitLocation, rotator(-HitNormal)); } }
Code:
simulated function Explode(vector HitLocation, vector HitNormal) { local vector start; local rotator rot; local int i; local FlakChunk NewChunk; start = Location + 10 * HitNormal; if ( Role == ROLE_Authority ) { HurtRadius(damage, 220, MyDamageType, MomentumTransfer, HitLocation); for (i=0; i<6; i++) { rot = Rotation; rot.yaw += FRand()*32000-16000; rot.pitch += FRand()*32000-16000; rot.roll += FRand()*32000-16000; NewChunk = Spawn( class 'FlakChunk',, '', Start, rot); } } Destroy(); }
At the end it als destroys itself, this is because once the shell has exploded, it has finsihed it's task
Anyhow hope this all helps... take a look through http://wiki.beyondunreal.com , it's a good read
Leave a comment: