Announcement

Collapse
No announcement yet.

Need help regarding FGM-148 Javelin alike Weapon

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

  • replied
    I still don't understand what this piece of code is supposed to do since it is relative to the world grid system, not necessarily your target's location

    Code:
    	simulated function TimerToNext()
    	{
    		WorldInfo.Game.Broadcast(self,"Is In TimerToNext:");
    		
    		/*Conditions for the rocket to start climbing down*/
    		if(Location.X < 0)
    		{
    			if(Location.X >= WhoTargeted.Location.X)
    			{
    				GoToState('TravelToTarget');
    			}
    		}
    		if(Location.X > 0) // why are you checking in only one of the horizontal axes against 0?
    		{
    			if(Location.X <= WhoTargeted.Location.X) // why are you checking in only one of the horizontal axes? The Z-axis would make more sense to me since it is vertical
    			{
    				GoToState('TravelToTarget');
    			}
    		}
    	}
    Since "direction" in game is all relative to which way the player is facing, we'd need a bit more info about how your are testing this to help solve it. Does the missile always go left no matter which way you are aiming? Is your target in the center of the map at world coordinates 0,0,0? If you place the target somewhere else in the map does the missile behave the same?

    VSize returns the length of the vector you pass into it. The VSize check I posted earlier needs to be tweaked to also take into account if the missile has overshot the target (very easy to do if its moving fast), to drop into the travel to target state. This can be checked by using the 'dot' product.

    Code:
    const BEGINTOTRAVELDOWNDIST=500; // set this to whatever value seems reasonable
    
    function SomeFunctionOrTimerName
    local vector vDist2d, vDir, vDir2d;
    
    vDist2d = Target.location - location;
    vDist2d.z = 0;//toss out the vertical component
    vDir = Velocity; // maybe use this later
    vDir2d = vDir;
    vDir2d.z=0;
     // if the missile is close enough to the target overhead in the horizontal plain, 
    // OR has already passed over the target (since the vector dot product returned 
    // something less than 0), then turn down and travel to the target
    if(Vsize(vDist2d) < BEGINTOTRAVELDOWNDIST || (vDist2d dot vDir2d < 0) )
         GotoState("TravelToTarget");

    Leave a comment:


  • replied
    Alright, so what we did was made some changes in 2 states (thanks to meowcat for giving us the idea)

    Gain Altitude
    Code:
    event BeginState(name PreviousStateName)
    	{
    		HitActor = WhoTargeted;
    		
    		WorldInfo.Game.Broadcast(self,"In GainAltitude State!");
    		
    		/*Used a Dummy as a target point for the rocket to launch to*/
    		if(HitActor != None)
    		{
    			Acceleration = 500 * Normal((HitActor.Location - Location) + vect(0,0,3000));
    		}
    		else
    		{
    			Acceleration = 800 * Normal(Location - Location);
    		}
    		SetTimer(0.1,True,'TimerToNext');
    	}
    	
    	simulated function TimerToNext()
    	{
    		WorldInfo.Game.Broadcast(self,"Is In TimerToNext:");
    		
    		/*Conditions for the rocket to start climbing down*/
    		if(Location.X < 0)
    		{
    			if(Location.X >= WhoTargeted.Location.X)
    			{
    				GoToState('TravelToTarget');
    			}
    		}
    		if(Location.X > 0)
    		{
    			if(Location.X <= WhoTargeted.Location.X)
    			{
    				GoToState('TravelToTarget');
    			}
    		}
    	}
    Travel to Target
    Code:
    simulated function Timer()
    	{
    		if( WhoTargeted != None && WhoTargeted != Instigator )
    		{
    			RotateVector( Velocity, WhoTargeted.Location - Location , TurnRate * TimerRate );
    			Acceleration = 5000 * (WhoTargeted.Location - Location); //Make the Rocket click to the target, and make it faster
    			//Velocity = Normal(Velocity) * (Vsize(Velocity) + 20);
    			SetRotation( rotator( Velocity) );
    			WorldInfo.Game.Broadcast(self,"WhoTargeted:"@WhoTargeted@"");
    		}
    	}
    Right now, it will move toward the dummy direction spawned on top of the enemy and just shoots down

    It will still curve when the target moves too fast but we compensate it by making the descent very fast so the eye cant catch it (temporary solution)

    To our understanding, there is a hemisphere in front of the rocket which detects other actor if we used vsize

    We didn't use the vsize because we noticed that if the target is too near, it will just fire straight at the enemy and if the rocket moves too high it will not descend (we think it can be 'corrected' given the correct value)
    -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    So, right now we want your opinion on whether the changes we made

    1. Were efficient
    2. Is there a better way to do it
    3. We should try to use back meowcat method (we had problems with this one)
    - The rocket have the tendencies to shoot wayyy to the side(Left of the player) and goes to the middle of the cube in the test map

    Thanks

    Leave a comment:


  • replied
    Thanks for the tips meowcat

    It's actually for a 3D environment (not game, just mere tinkering)

    Leave a comment:


  • replied
    Ok, a few thoughts (without having tested this code in game myself): (also is this for a 2d game (like a sidescroller), or full 3d?)
    1. I'm not quite sure what the Location.component check (x and y) is doing in the 'TimerToNext' function in that it seems that the behavior would look funny if you fired this missile from a different direction (i.e. aiming away from the target). If the missile is going basically straight up, the Z component should change with respect to the target, but I'm not sure that the missile's X and Y components would ever exceed the target's x and y as those are absolute world coordinates (and the current code appears to rely on the fact that the missile spawns from a location whose X and Y values are smaller than the targets, and that the missile initially travels in a direction that would "increase" he values of the X and Y location components). This check may be made simpler by just comparing the 2D distance to the target and then begin nosing the missile down once the 2D distance gets small.

    2. You might able to simplify this flight path by first performing a 'trace' check above the target for some maximum distance (to see if it is clear overhead), and then base the gain altitude path on this overhead location (assuming a static target)

    So for some pseudo code (note these are not necessarily all the correct parameters as I'm going from memory):
    Code:
    var vector vTopTarget;
    const MAXHEIGHT=4000;
    
    state GainAltitude
    {
    	event BeginState(name PreviousStateName)
    	{
                    local vector HitLoc, HitNorm;
                    local actor HitActor;
    		WorldInfo.Game.Broadcast(self,"In GainAltitude State!");
    		// grab the over head location
    		HitActor = Trace(HitLoc, HitNorm, WhoTargeted.location + vect(0,0,MAXHEIGHT) ,WhoTargeted.location,true);
    		if(HitActor != none)  vTopTarget = HitLoc - vect(0,0,200); // drop down a bit to allow room to maneuver
    		else vTopTarget = HitLoc;
    		Acceleration = 800 * Normal(vTopTarget - location); // accelerate towards the overhead location
    		//Acceleration = 800 * Normal(Vector(ElevateRotator));
    		SetTimer(0.1,True,'TimerToNext');
    		
    	}
    // for this function you could probably update the vTopTarget vector as well to dynamically track, or just keep the missile gaining altitude while heading in the target's direction, then drop down on top
    	simulated function TimerToNext()
    	{
    		local vector vTwoDdist;
    		WorldInfo.Game.Broadcast(self,"Is In TimerToNext:");
    		vTwoDdist = WhoTargeted.location - location;
    		vTwoDdist.z=0; // map it to two dimensions
    		if(VSize(vTwoDdist) < 300) // this could be whatever distance is appropriate for the scale of your map/game, maybe scale it according to the overall distance too
    		{
    			GoToState('TravelToTarget');
    		}
    	}
    	
    	simulated function EndState(Name NextStateName)
    	{
    		ClearTimer('GainAltitude');
    		ClearTimer('TimerToNext');
    		Super.EndState(NextStateName);
    	}
    }
    Some of the seeking code from the old UT2k4 seeking rocket (seekingRocketProj) might work well here too for when you want to zero in on the target:

    Code:
    var actor Seeking;
    var vector InitialDir;
    // this timer was set to be called every 0.1 seconds
    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
    			// tweaking the 0.8 here or 0.5 in the next line is what 'weighted' how 
    			// closely the missile tracked the target, changing it to something like 
    			// 100 or greater would essentially negate the effect of the current velocity 
    			// (or just leave out the "+ Velocity") and give perfect targeting.
    			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));
        }
    }

    Leave a comment:


  • started a topic Need help regarding FGM-148 Javelin alike Weapon

    Need help regarding FGM-148 Javelin alike Weapon

    Hello,

    So my team and I were trying to create a Javelin as part of our training

    There are 3 states when the projectile is fired

    1. Launched
    2. Gain altitude
    3. Travel to Target

    We encounter 2 problems so far

    1. The rocket fired have a tendency to 'swim' horizontally towards the target instead of going up
    2. Right now, the rocket curves upward then downward to the target



    What we wanted to do is this



    PS: I'm aware that this is not the exact javelin missile flight path, it's just something we wanted to do

    We were wondering on how to get the rocket in the GainAltitude state to reach on top of the target and then jump into the 3rd state and just have it go downwards towards the target


    MYWeap_Javelin (We're using rocket launcher properties and all)

    Code:
    class MyWeap_JavelinExtend extends UTWeapon;
    
    //Variables that are used in RocketLauncher
    
    // We are using UDK lock on functions in RocketLauncher, so its quite long 
    
    simulated function Projectile ProjectileFire()
    {
    	local Projectile SpawnedProjectile;
    
    	SpawnedProjectile = super.ProjectileFire();
    	if (bLockedOnTarget && MYProj_Javelin(SpawnedProjectile) != None)
    	{
    		MYProj_Javelin(SpawnedProjectile).WhoTargeted = LockedTarget;
    	}
    
    	return SpawnedProjectile;
    }
    
    defaultproperties
    {
    	/*properties*/
    }
    MYProj_Javelin
    Code:
    class MYProj_Javelin extends UTProj_Rocket;
    
    var float SpeedVelocity;
    var() Rotator ElevateRotator;
    var Float MaxAngleDelta;
    var Float MaxTargetRadius;
    var Actor WhoTargeted;
    var() float TurnRate;
    var float TimerRate;
    
    auto state Launched
    {
    	event BeginState(name PreviousStateName)
    	{
    		WorldInfo.Game.Broadcast(self,"In Launched State!");
    		Speed=500;
    		SetTimer(0.2,false,'NextStatePlease');
    	}
    	
    	simulated function EndState(Name NextStateName)
    	{
    		ClearTimer('Launched');
    		Super.EndState(NextStateName);
    	}
    	
    	function NextStatePlease()
    	{
    		GoToState('GainAltitude');
    	}
    }
    
    state GainAltitude
    {
    	event BeginState(name PreviousStateName)
    	{
    		WorldInfo.Game.Broadcast(self,"In GainAltitude State!");
    		Acceleration = 800 * Normal(Vector(ElevateRotator));
    		SetTimer(0.1,True,'TimerToNext');
    	}
    	
    	simulated function TimerToNext()
    	{
    		WorldInfo.Game.Broadcast(self,"Is In TimerToNext:");
    		if(Location.X >= WhoTargeted.Location.X || Location.Y >= WhoTargeted.Location.Y)
    		{
    			GoToState('TravelToTarget');
    		}
    	}
    	
    	simulated function EndState(Name NextStateName)
    	{
    		ClearTimer('GainAltitude');
    		ClearTimer('TimerToNext');
    		Super.EndState(NextStateName);
    	}
    }
    
    state TravelToTarget
    {
    	event BeginState(name PreviousStateName)
    	{
    		SetTimer(0.05, True,'Timer');
    	}
    	
    	
    	simulated function Timer()
    	{
    		if( WhoTargeted != None && WhoTargeted != Instigator )
    		{
    			RotateVector( Velocity, WhoTargeted.Location - Location , TurnRate * TimerRate );
    			Velocity = Normal(Velocity) * (Vsize(Velocity) + 20);
    			SetRotation( rotator( Velocity) );
    			WorldInfo.Game.Broadcast(self,"WhoTargeted:"@WhoTargeted@"");
    		}
    	}
     
    	defaultproperties
    	{
    		TurnRate=185.00 //how many degrees per second
    		TimerRate=0.05
    	}
    }
    
    static final function RotateVector( out vector A, vector B, float Degree )
    {
    	local float Magnitude;
    	local vector C;
     
    	Degree = Degree * Pi / 180.0;//Convert to radians.
    	Magnitude = VSize(A);
    	A = Normal(A);
    	B = Normal(B);
     
    	if( A Dot B == -1.0 )//Vectors are pointing in opposite directions.
    		B.x += 0.0001;//fudge it a little
     
    	C = Normal(B - (A Dot B) * A);//This forms a right angle with A
     
    	A = Normal( A * Cos(Degree) + C * Sin(Degree) ) * Magnitude;
    }
    
    defaultproperties
    {
    	ElevateRotator=(Pitch=16384,Yaw=0,Roll=0)
    	MaxAngleDelta=1
    	MaxTargetRadius=100000
        bRotationFollowsVelocity=true
    	CheckRadius=0.0
    	BaseTrackingStrength=10000.0
    	HomingTrackingStrength=16.0
    }
    So any ideas on how to solve this problem ? Any help or ideas are welcomed

    Thanks

    Link to classes
    http://sdrv.ms/X8mHAQ
Working...
X