Game Development Reference
In-Depth Information
We start by defining our local variables. We set MyPawnOwner to be the pawn that the
HUD is currently drawn for. Our weapon, W , is our pawn's currently equipped weapon.
If we don't have a pawn for whatever reason, get out of the function. There is no point
in wasting precious CPU cycles if there is no need for the function to get called.
The next step involves our trace. We need to set the values for our trace,
then perform one.
/** If we have a weapon... */
if ( W != None)
/** Values for the trace */
StartTrace = W.InstantFireStartTrace();
EndTrace = StartTrace + W.MaxRange() *
HitActor = MyPawnOwner.Trace(HitLocation, HitNormal,
EndTrace, StartTrace, true, vect(0,0,0),,
DrawDebugLine(StartTrace, EndTrace, 100,100,100,);
A trace draws a direct line from one point to another. In this situation we have our
trace call our weapon's InstanteFireStartTrace() function, which in turn
calls GetPhysicalFireStartLoc() , which looks like the following code snippet:
* Location that projectiles will spawn from. Works for secondary
* fire on third person mesh
simulated function vector GetPhysicalFireStartLoc(optional vector
Local SkeletalMeshComponent AttachedMesh;
local vector SocketLocation;
Local TutorialPawn TutPawn;
TutPawn = TutorialPawn(Owner);
AttachedMesh = TutPawn.CurrentWeaponAttachment.Mesh;
(MuzzleFlashSocket, SocketLocation);
return SocketLocation;
Quite simply, we're using our weapon's SocketLocation to start the trace. Our
trace end uses the StartTrace value and adds our weapon's MaxRange , then
multiplies it by our player controller's rotation. The HitActor value keeps track
of anything our trace hits along the way.
Search Nedrilad ::

Custom Search