UnrealScript Game Programming Cookbook

(Chris Devlin) #1
Chapter 6

155


  1. If our weapon is destroyed or we are destroyed, then we want to prevent the
    weapon from continuing to lock onto a target.
    /****

    • If the weapon is destroyed, cancel any target lock
      ****/
      simulated event Destroyed()
      {




// Used to adjust the LockTarget.
AdjustLockTarget(none);

//Calls the previously defined Destroyed function
super.Destroyed();
}


  1. Our next chunk of code is pretty large, but don't let it intimidate you. Take your time
    and read it through to have a thorough understanding of what is occurring. When it
    all boils down, the CheckTargetLock() function verifies that we've actually locked
    onto our target.
    We start by checking that we have a pawn, a player controller, and that we are
    using a weapon which can lock onto a target. We then check if we can lock onto
    the target, and if it is possible, we do it. At the moment we only have the ability
    to lock onto pawns.
    /*****

    • Have we locked onto our target?
      ****/
      function CheckTargetLock()
      {
      local Actor BestTarget, HitActor, TA;
      local UDKBot BotController;
      local vector StartTrace, EndTrace, Aim, HitLocation,
      HitNormal;
      local rotator AimRot;
      local float BestAim, BestDist;




if((Instigator == None)||(Instigator.Controller ==
None)||(self != Instigator.Weapon) )
{
return;
}
Free download pdf