Announcement

Collapse
No announcement yet.

Need help with weapon lockon code.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Need help with weapon lockon code.

    Here is some code I took from the tick function of the RocketLauncher, and used it in a vehicle-mounted weapon. This is the code that makes the rocket launcher "lock on" to a player. Eventually"Other" is passed to the projectile that this weapon fires so it can home in on the target. It all seems to be working (the projectiles track and follow the target), except that it seems one does not have to have the crosshairs ON the target for it to be locked on to, and sometimes it won't lock on if the crosshairs ARE on the target.

    Code:
    StartTrace = Instigator.Location + Instigator.EyePosition();
            Aim = Instigator.GetViewRotation();
    
            BestAim = LockAim;
            Other = Instigator.Controller.PickTarget(BestAim, BestDist, Vector(Aim), StartTrace, SeekRange);
    My problem is that I don't quite see how this works, even after checking out the PickTarget function in Controller.
    Code:
    native(531) final function pawn PickTarget(out float bestAim, out float bestDist, vector FireDir, vector projStart, float MaxRange);
    Can someone explain how this works so I can make whatever adjustments I need it would be appreciated. Thanks.

    #2
    My Psychic Code Intuition (TM) system is telling me that your SeekRange is too large.

    The function accepts 5 inputs (out float bestAim, out float bestDist, vector FireDir, vector projStart, float MaxRange).

    bestAim is an out parameter, so it gets "returned", and so does bestDist (which is probably the distance to the final target, and bestAim also is returned for the final target, whatever it does). The MaxRange (which you call SeekRange in your code) is probably the range with which the code is allowed to search for targets. If the value is too small, it will be more difficult to find a target, and if its too large, it might find a target off aim.

    Just a hunch, though.

    Comment


      #3
      OK, I think I have this figured out. There seems to be a value passed to the native code as 'BestAim', as well as an out value. I noticed that in defaultproperties one can find: Lockaim=0.99600. The only place Lockaim is used is in the statement just before the picktarget function is called. If I change the value of Lockaim, the "target area" changes in size.
      I am not sure how this is calculated though, because when 'seekrange' is changed, the distance a target can be detected changes, but also the "width" of the scan area. Adjusting Lockaim once the seekrange is set where it is needed lets you fine-tune the scan width.

      Comment

      Working...
      X