# Guided projectile

Does anyone have an idea or code example  how to create a guided projectile (ie the projectile which would follow a moving node until it collides with it)?

THanks!

I'm a noob here so use this only if it is your last option Probably there is better ways to get it done.

On each update cycle calculate if the target location (x2-y2) is left or right of the guided node trayectory. This trayectory can be expressed by a segment between the guided node location (x0-y0) and another point (x1-y1) on the guided node current trayectory which can be calculated by adding the location and bearing of the guided node.

Depending on outcome steer the guided node one way or another.

Here is a delphi example of the algorithm

// if result < 0 then x2y2 point is left of the line

// if result > 0 then x2y2 point is right of the line

// if result = 0 then x2y2 point is on line

function turns( x0, y0, x1, y1, x2, y2 : double ) : double;

begin

result := ( x1 - x0 ) * ( y2 - y0 ) - ( x2 - x0 ) *( y1 - y0 );

end;

Repeat same code for vertical plane and there you have it .

Regards

–kxl

BTW, here is a link to an old algorithm faq http://www.faqs.org/faqs/graphics/algorithms-faq/. It’s usefull to read this kind of stuff.

Enjoy  }:-@

-kxl

… and put the code into a Controller which You attach to Your guided missile spatial to get it updated regularily

kaspaxl said:

I'm a noob here so use this only if it is your last option ;) Probably there is better ways to get it done.

On each update cycle calculate if the target location (x2-y2) is left or right of the guided node trayectory. This trayectory can be expressed by a segment between the guided node location (x0-y0) and another point (x1-y1) on the guided node current trayectory which can be calculated by adding the location and bearing of the guided node.

Depending on outcome steer the guided node one way or another.

Here is a delphi example of the algorithm

// if result < 0 then x2y2 point is left of the line
// if result > 0 then x2y2 point is right of the line
// if result = 0 then x2y2 point is on line
function turns( x0, y0, x1, y1, x2, y2 : double ) : double;
begin
result := ( x1 - x0 ) * ( y2 - y0 ) - ( x2 - x0 ) *( y1 - y0 );
end;

Repeat same code for vertical plane and there you have it :) .

Regards
--kxl

That looks like the cross product of a 2d vector.

Jme vector have a function called cross that will return something useful. The direction of the vector will define the axes you need to use to turn. You can use Quaternion's functions to rotate the node.