Message Board


Message Board > Fenix / Bennu / Gemix / DIV > homing missiles

December 31, 2006, 05:47
AJZ
Beardless
5 posts
I recall a site somewhere that had some example code that showed how to use angle functions to create missiles that home in on the closest target. Has anyone heard of such a thing, as I've forgotten the name of the site. All I remember is that it was definitely in Spanish, and that there were plenty of other tutorials on the site.

Failing that, does anyone have an example of such a thing? Thanx!!
____________
#
December 31, 2006, 12:18
Eckolin
Quite Whiskered
388 posts

You can use near_angle to turn towards some target. To find the closest enemy you could calculate the distance to all targets (every few frames) and take the closest.

In code it might look like this.


Code:
process rocket(x,y,angle);
Private
  temp_dist;
  temp_id;
  closest_dist;
  closest_id;
begin
  graph=1;
  loop
    closest_dist=MAX_INT;
    closest_id=0;
    while (temp_id=get_id(type enemy))
      if ((temp_dist=fget_dist(x,y,temp_id.x,temp_id.y))<closest_dist)
        closest_id=temp_id;
        closest_dist=temp_dist;
      end
    end
    if (exists(closest_id))
        angle=near_angle(angle,fget_angle(x,y,closest_id.x,closest_id.y),5000)
    end
    advance(10);
    frame;
  end
end


[Edited on December 31, 2006 by Eckolin]
____________
Maker of Games...
Wisdom is supreme; therefore get wisdom.
Need help with coding? I probably wrote something similar.
#
December 31, 2006, 17:12
Sandman
F3n!x0r
1194 posts

Eckolin: doesn't your code check the closest target every frame and thus switch targets if another target gets closer than the first? I dunno if that's what's wanted, but it seems weird for a rocket and to check the closest target takes relatively much power.
Well of course you know this, but I just thought I'd point it out.
____________
BennuWiki
Yes, my avatar has grey borders in IE (so get a decent browser)
ROOFLEZ ROOFLEZ
#
January 6, 2007, 15:14
AJZ
Beardless
5 posts
I changed fget_dist to fget_angle and shifted some parameters around, and it works for my purposes just fine. The homing missiles are just one part of a multi-weapon system I built into my game, and they (I use two processes of them) are pretty much "clean-up" weapons.

Thanx for the code.
____________
#

Message Board > Fenix / Bennu / Gemix / DIV > homing missiles

Quick reply


You must log in or register to post.
Copyright © 2005 Booleansoup.com
Questions? Comments? Bug reports? Contact us!