|
-
Need Some Help With AI
K, I have a game where you can do certain moves at certain times, I represent those times by having a variable set to true whenever you can and false when you cant. This works fine with one enemy on screen, but when I add the second one the variable gets messed up by the second enemy so it wont work right. I fixed some of that by limited the enemy's distance of AI, though eventually you'll be able to bring the 2 enemies close to each other so that doesnt help much. Right now I have 1 option and its to use different Variable for each enemy, this will mean that I have to have a if statement for every variable I use. Which will probably turn into a big mess. So any ideas on how I can fix this? Sorry if its confusing, but there isnt really an easy way to put this.
-
If I were you I would have all the enemies instantiate the variable rather than creating the variables on main timeline. That way you can have each enemy check its own variable if it is true or false. So for example, if I wanted 5 enemies to check if it can punch I would write:
code:
//This for loop creates the variable punchAble for each of your 5 enemies
//on the screen.
for (var i=0; i<5; i++) {
_root["enemy"+i].punchAble = true;
}
//The for loop checks whether the punchAble variable is set to true
//for each enemy.
for (var i=0; i<5; i++) {
if (_root["enemy"+i].punchAble == true) {
//enemy can punch
}
}
-
K, I was doing something along those lines, but I was using variable+i == true so it wasnt working...heh..thanks
-
K that didnt work either, for some reason, it only checks if the highest number is true or not so it only works on 1 enemy....I have the loop in a Key.isDown code, does that matter?
-
Actually, that could also work. Maybe you were using the wrong syntax, but you were close. I think it should be:
code:
_root["variable"+i] == true
But I'd rather have each enemy house its own properties and methods for doing its stuff .
-
I have to see how you setup everything to get an idea of what's wrong. Do your enemies have instant names: enemy0, enemy1, etc. Are they on the main timeline, is your Key.isDown on the main timeline as well? Sorry, but I need more info.
-
no, I was using the same syntax you posted, I was just saying the way of it.
Its not working for some reason. It only checks if the highest number is true or not.
-
My Enemies are the main timeline, the Key.isDown is inside of the main character.
-
Well, the variable is definitely set for each enemy. Do a trace statement in the second for loop and you should get true for all enemies.
There should be no problem with having the code inside the main character. Just as long as you use _root to reference the enemies (since they are outside of the main character's timeline)
-
Yea I do use _root, I know all the stuff
-
hmm, when I do trace it comes out as true, but then the other ones are false. Is there any way to make it so that if ANY of them are = to true then it does it?
-
 Originally Posted by The_Mercenary
hmm, when I do trace it comes out as true, but then the other ones are false. Is there any way to make it so that if ANY of them are = to true then it does it?
Hmm...thats a good question. Try writing a script that determines the value of the variable for each enemy. If the variable is equal to true, than do the action. I'm a bit lost here, but what exactly decides if the enemy can do a certain move?
-
Its not the enemy that does a certain move, it lets you do a certain move on them when their in a particular state.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|