Targeting Nearest Enemy & Rangefinding - updated

Talk about making games.

Targeting Nearest Enemy & Rangefinding - updated

Postby feral » Wed Jul 30, 2008 10:55 pm

hominggrab.jpg


This should solve the "Tower Defense" type questions and the "Sonic Homing Attack" questions

sorry for the delays, I will post tutorial/explanations soon... but, as I promised an update today ....I am posting the "code" now.

attached is a very very rough demo of targeting/shooting the closest enemy and moving towards the closest
homing.zip
data and ged
(36.11 KiB) Downloaded 285 times


it basically uses a "bubble sort", but instead of creating a separate "array" and copying sprite info then using the array to do the bubble sort, this method simply uses screen draw event of each enemy to update their own data into a sort engine (ie: sorts out who is closest)

of course using an array is probably better in some respects, but for newcomers and for basic games i think this is easier to follow.

This version will then select the closest and then target it until dead...even if another enemy gets closer still..

This can be changed, so that the bullet/missile will change directions and attack a different target if the new target is closer then the currently targeted one.. this will be cool for some games ( with guided type missiles) but for other games looks silly because the bullet bounces all over while picking a target..


I will do a complete explanation soon, in the mean time the code is pretty well documented.. so if you read it through and still have questions let me know.

Also, if there are any particular uses for this, or any game scenarios or requests (about this particular concept) let me know and i will try to fit it into the tutorials.

and yes I will do an example for SONIC soon. 8)

and an example on how to use this to do rangefinding and targeting as in tower defense type games.. all coming soon

feral

oh .. PS: this version currently only does 1 type of enemy... but, if you read through the code, you can see I am ready to implement it, so that you can pick the nearest of any particular type of enemy...

for example if I have a rocket launcher, I need to know the nearest helicopter, not the nearest soldier, even if the soldier is closer.. this code will do that too..
Last edited by feral on Sat Aug 02, 2008 4:12 am, edited 5 times in total.
User avatar
feral
 
Posts: 308
Joined: Sun Mar 16, 2008 6:27 am
Score: 47 Give a positive score

Re: Targeting Nearest Enemy & Rangefinding - soon

Postby stevenp » Wed Jul 30, 2008 11:33 pm

nice +1
User avatar
stevenp
 
Posts: 403
Joined: Sat Dec 22, 2007 12:49 pm
Location: canada, ontario
Score: 16 Give a positive score

Re: Targeting Nearest Enemy & Rangefinding - soon

Postby sonicunleashed » Thu Jul 31, 2008 4:56 pm

thank you feral i really aprecait this :D 8) 8) :D :D :D :mrgreen: :mrgreen:
sonicunleashed
 
Posts: 19
Joined: Fri Jul 18, 2008 12:44 am
Score: 0 Give a positive score

Re: Targeting Nearest Enemy & Rangefinding - soon

Postby sonicunleashed » Thu Jul 31, 2008 5:35 pm

hey feral can you make sonic the person you play with instead of the game editor icon guy :wink: :roll:
Attachments
Neoze2.zip
(77.53 KiB) Downloaded 209 times
sonicunleashed
 
Posts: 19
Joined: Fri Jul 18, 2008 12:44 am
Score: 0 Give a positive score


Return to Game Development

Who is online

Users browsing this forum: No registered users and 1 guest