Making Enemy AI A Little Human?

Hi, 

I’ve been working on this problem for a few days now and am having a hard time find anything on the internet that can point me in the right direction.

I’m trying to make an enemy AI that has a kind of random error on what it think it should do.  I can make the enemy respond how it should when the user does something (like punching) but I don’t want the enemy to dodge every single punch.  Any ideas of how I can make my enemy a little more human?

Quick simple way. In the code where enemy AI reacts to user’s punch; generate a random number, and if the number is < then a certain value, then dodge the punch, otherwise tell the AI to take the punch.

local reactFlag =  (math.random(10) < 8)

if reactFlag == true then

   – dodge the punch

else

  – take the hit

end

Once the AI unit is tired or injured you can reduce the number 8 down to maybe 5, then the AI is at a 50/50 chance to wether it will dodge the punch. These are very arbitrary numbers. Use whatever range you want.

Of course to make it more human you can adjust for wether the punch is a left or right and change the 8 up or down, where AI may be more likely to block the right handed punches, or maybe more likely to dodge a certain type of punch.  I like adjusting for fatigue or injury. That will give it more human feel.

Clearly AI, is a lot more complex then this.  But this should get you going down the right path.

Good luck.

That’s genius! I was thinking of something using a random number but had no clue how to execute it.

Thank you!!! 

Quick simple way. In the code where enemy AI reacts to user’s punch; generate a random number, and if the number is < then a certain value, then dodge the punch, otherwise tell the AI to take the punch.

local reactFlag =  (math.random(10) < 8)

if reactFlag == true then

   – dodge the punch

else

  – take the hit

end

Once the AI unit is tired or injured you can reduce the number 8 down to maybe 5, then the AI is at a 50/50 chance to wether it will dodge the punch. These are very arbitrary numbers. Use whatever range you want.

Of course to make it more human you can adjust for wether the punch is a left or right and change the 8 up or down, where AI may be more likely to block the right handed punches, or maybe more likely to dodge a certain type of punch.  I like adjusting for fatigue or injury. That will give it more human feel.

Clearly AI, is a lot more complex then this.  But this should get you going down the right path.

Good luck.

That’s genius! I was thinking of something using a random number but had no clue how to execute it.

Thank you!!!