I'm writing a simple enemy AI for a game I'm making, and as of now it should just have two different attacks which would be picked randomly(even tho its just one or the other, but hey...) here's how it should be working:
I made a "dice" that will only generate a number when the player is in range, then stop. If the player is in range the enemy will start attacking based on what number was thrown and turn the dice back on afterwards. The dice will generate a new number and the next attack should follow.
It does this pretty nicely some times, however sometimes it simply keeps throwing numbers making the enemy use multiple attacks at the time. I can't seem to find out why tho, does anybody know where I went wrong?
Here's the script:
asked Dec 15 '11 at 05:33 PM
I think that the problem relies on the absence of a lock, that will "block" the Update call when the action have already took place. In other words, I think that the Update procedure is a bit long to "stay" in a single frame; that is, you could have multiple calls to the Attack() function in a single frame, and the result is an enemy that attacks many times, even if his "turn" would be finished.
I would modify the script in the following way:
Declaring a boolean function at the beginning:
Then, modify the Update() function this way:
Hope that it works. Let me know...
answered Dec 16 '11 at 07:52 AM