Tutorial-Heat Seeking Rockets.

  • Two Factor Authentication is now available on BeyondUnreal Forums. To configure it, visit your Profile and look for the "Two Step Verification" option on the left side. We can send codes via email (may be slower) or you can set up any TOTP Authenticator app on your phone (Authy, Google Authenticator, etc) to deliver codes. It is highly recommended that you configure this to keep your account safe.

Postal

I apear to have lost my pin.
Nov 14, 1999
1,388
0
0
WoD.BeyondUnreal.com
Long time ago, WoD used to have tutorials and classes, now it seems to mostly be a close group of nuts rambling. Perhaps if we have something usefull, we may get some more traffic. So I thought perhaps I could try and make some real content like a simple tutorial or so, like this:
--------------------------------------------------------------------------
040808 Heat Seeking Rockets
-Postal

Allright boys and girls, here's a simple way to turn the rocket launchers seeking (lock on) rockets into homing (self-lock on) rockets.

If you look at the rocket projectile (class rocketproj), its simple enough, flies in a strait line unless its in a group. Then we got the class SeekingRocketProj where this rocket will home in on a target given to it. So, lets tell it how to get its own target.

In the SeekingRocketProj class, all the code for homing is in the Timer, which is called tenth of a second.
Code:
simulated function Timer()
{
    local vector ForceDir;
    local float VelMag;

    if ( InitialDir == vect(0,0,0) )
        InitialDir = Normal(Velocity);
         
	Acceleration = vect(0,0,0);
    Super.Timer();
    if ( (Seeking != None) && (Seeking != Instigator) ) 
    {
		// Do normal guidance to target.
		ForceDir = Normal(Seeking.Location - Location);
		
		if( (ForceDir Dot InitialDir) > 0 )
		{
			VelMag = VSize(Velocity);
		
			// track vehicles better
			if ( Seeking.Physics == PHYS_Karma )
				ForceDir = Normal(ForceDir * 0.8 * VelMag + Velocity);
			else
				ForceDir = Normal(ForceDir * 0.5 * VelMag + Velocity);
			Velocity =  VelMag * ForceDir;  
			Acceleration += 5 * ForceDir; 
		}
		// Update rocket so it faces in the direction its going.
		SetRotation(rotator(Velocity));
    }
}

So it allready knows to fly fowards, and turn towards a target. Perfect, all we gotta do it give it a target, or better yet, have it find its own target.

So, what to do, how about we have the rocket use a Foreach VisibleCollidingActors to find pawns within a range of say, 2000 unreal units.
Searching for pawns will let the rocket aim in on vehicles and enemy players.
Code:
local Pawn Victims;
// If we dont have a target or if were aimed at our owner
	if ((Seeking==None)||(Seeking==Instigator))
	{
// Look for someone
		foreach VisibleCollidingActors(class 'Pawn', Victims, 2000,)
		{
// If they arnt my owner or dead.
			If (Victims != Instigator && Victims.Health >0)
			{
// Your'e then my new target
				Seeking = Victims;
			}
		}
	}

Plug that in before the line "if ( (Seeking != None) && (Seeking != Instigator) ) " and you got youre self a self homing rocket.

Fire and Forget.