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.
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..