UnrealScript Game Programming Cookbook

(Chris Devlin) #1

Weapons


152


  1. With our variables in place, we can now move onto the weapon's functionality. The
    InstantFireStartTrace() function is the same function we added in our weapon
    during our Chapter 3, Scripting a Camera System. It allows our weapon to start its trace
    from the correct location using the GetPhysicalFireStartLoc() function.
    As mentioned before, this simply grabs the rotation of the weapon's muzzle flash
    socket, and tells the weapon to fire projectiles from that location, using the socket's
    rotation. The same goes for GetEffectLocation(), which is where our muzzle
    flash will occur.


The v in vector for the InstantFireStartTrace() function is not
capitalized. The reason being that vector is actually of struct type,
and not a function, and that is standard procedure in UDK.

/********************************************************
* Overriden to use GetPhysicalFireStartLoc() instead of
* Instigator.GetWeaponStartTraceLocation()
* @returns position of trace start for instantfire()
********************************************************/
simulated function vector InstantFireStartTrace()
{
return GetPhysicalFireStartLoc();
}

/********************************************************
* Location that projectiles will spawn from. Works for secondary
fire on
* third person mesh
********************************************************/
simulated function vector GetPhysicalFireStartLoc(optional vector
AimDir)
{
Local SkeletalMeshComponent AttachedMesh;
local vector SocketLocation;
Local TutorialPawn TutPawn;

TutPawn = TutorialPawn(Owner);
AttachedMesh = TutPawn.CurrentWeaponAttachment.Mesh;
/** Check to prevent log spam, and the odd situation win
which a cast to type TutPawn can fail */
if (TutPawn != none)
{
AttachedMesh.GetSocketWorldLocationAndRotation
(MuzzleFlashSocket, SocketLocation);
}
Free download pdf