Finding closest attack target?
Hello everyone!
OK, I have an AI monster that must eat rabbits around him (lol). There are many rabbits around, but how do I know which direction I must go to catch the closest rabbit?
I was thinking maybe do a "spiral search" around the monster, but how?
Thanks!
for (int i = 0; i <= 360; i++)
//do a circle search!
or you could have the bunnies tell the monster how far they are away from him, so the monster just has to check a list and pick which one will be the easiest to get to ;)
//do a circle search!
or you could have the bunnies tell the monster how far they are away from him, so the monster just has to check a list and pick which one will be the easiest to get to ;)
That's my opinion.
"know which direction I must go to catch the closest rabbit"
1) Find the closest rabbit. This can be done by iterating over all rabbits, computing the distance and saving only the smallest one
2) Create a vector to that rabbit from your monsters position.
3) Compute the angle between the two vector (or a planar angle?).
What I did want to say is that when choosing a rabbit you might also want to take into account the direction to that rabbit and not only the distance. In Game Gems 5 there is good article about such a function that is easy to tweak and visualize.
1) Find the closest rabbit. This can be done by iterating over all rabbits, computing the distance and saving only the smallest one
2) Create a vector to that rabbit from your monsters position.
3) Compute the angle between the two vector (or a planar angle?).
What I did want to say is that when choosing a rabbit you might also want to take into account the direction to that rabbit and not only the distance. In Game Gems 5 there is good article about such a function that is easy to tweak and visualize.
Don't shoot! I'm with the science team.....
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement