Go toward closest actor, but when actor is destroyed, move toward the next closest actor.
Hi, I went through @tatiang 's move toward closest actor code (found here) and it's pretty great. I understand it for the most part and it's working, also for the most part.
What I have is a missile launcher that launches a missile that moves toward the closest target enemy and destroys it. The problem is if I have two missiles headed toward that enemy, and the first missile destroys it, the second one seems to forget to change course to the next closest enemy instead. I tested it out in the original demo as well to see how it affected things there if I made it so the hero would destroy the enemy when it touched it, and it also stopped moving. I switched the change functions into constrains and that didn't seem help either.
The closest I've gotten to making it reset itself in some meaningful way is to have a timer that resets a boolean and have the whole thing inside a rule that when that boolean turns on it should run the code again. It still doesn't catch them all the time though, a lot of my missiles appear on the screen and then just sit there and don't go anywhere.
So anyway, I'm trying to figure out some code that would set up the idea that it should move on to the next enemy if the original one it was assigned is gone. Any ideas?
Comments
I'm just bumping this. Maybe there's some way to make it so actors create a boolean column that says it's alive or dead, and that the missile checks that and if it's dead it goes to the next non-dead one? I guess that's almost the same thing.
Vote for Nearest Neighbor Scaling option in gamesalad! Let's make our games look truly stunning!