|
I am trying to create a function for a chain lightning attack in a tower defense game and I am unsure of how to prevent the chain attack from bouncing between the two same targets back and forth. Currently, I am using a collision sphere extending from the first target to get the closest enemy object but using simply this from the second target could potentially cause bouncing behavior. How can I counteract this? The function is currently being called by a missile object on collision with it's target. I am writing in JavaScript.
(comments are locked)
|
|
Keep a list of targets you've already hit, something like in your projectile. When you've found a target to jump to, see if the target already exists in your list using If it's already there, don't jump to it and find the next target that isn't already in your list. When you find that target, add it to the jump to it and add it to the list: The whole check might look something like: This seems like a valid solution for my problem. I'll try and implement this. Is there any reason a list is used instead of an array?
Jul 14 '11 at 03:24 PM
nostagmus
Lists contain built-in methods for determining whether something is in them (as you can see in the code example) and are pretty easy to work with (you get
Jul 14 '11 at 03:41 PM
burnumd
PS, I edited the answer to provide more clarity on what you'd do to check if you've already hit the target.
Jul 14 '11 at 03:49 PM
burnumd
(comments are locked)
|
|
Each target has a boolean flag in it, "alreadyHit". When they get hit, set that true. Further checks ignore any target with that set true. When the whole attack is done, set all of these flags to false. It's better to not have to modify the target class if you don't have to. They shouldn't need to have any logic that's weapon specific, so it makes more sense to make the weapon aware of what it's doing rather than making the targets have to handle some special case for a specific weapon.
Jul 14 '11 at 03:20 PM
burnumd
I prefer not having to scan a list on each collision.
Jul 14 '11 at 03:22 PM
almo
(comments are locked)
|
