Help with A.I

Blitz3D Forums/Blitz3D Programming/Help with A.I

cash(Posted 2004) [#1]
I have looked into the physics of AI in games and understand what it required, but i am having trouble
implementing this in Blitz. Al I want is for the enemies
to do a bit more than just wander around and attack.

eg If i shoot one it turns and runs away. Problem is getting the timings on the animations to work properly.

Should I be using timers to change states, or does anyone have any other suggestions.

I have looked at a lot of code examples which outline the basics, but implementation is the problem.


semar(Posted 2004) [#2]
Yes, give a status to your objects, and make them act accordingly, with the proper animation too.

For example, at the beginning of the game, the enemy should stay in an 'IDLE' status. You may create a different function for each status, for example:
select enemy\status
Case S_IDLE
    DO_IDLE(enemy)
case S_ESCAPE
    DO_ESCAPE(enemy)
.
.
end select   


Each DO_something is a function which is called from within the main loop, and the enemy object is passed as parameter.

About taking initiative for a better A.I., you can set a variable in some function (for example for the IDLE function), and when a certain amount of seconds are passed -that amount could also be random - then change the status to another one, for example move the enemy from its position to a random one in the level.

More, you can make your A.I. reacting to the player action; if, for example, your enemy is in an IDLE status, and the player moves near to him, then change the status to ATTACK, which will move the enemy toward the player, and then, when the player is in view, change the status again to S_SHOOT, which will play the shooting animation, and bullets will be fired to the player.

And so on. If the enemy is shooted, you can decide to react suddenly (escape or respond to attack); basically, the A.I. is a mix of timing and random decision, accordingly also with the enemy weapon, its damage, the player damage, and so on..

If you want to see an example of what I've described, you can point your browser on my web site, and play with Dangerous Robots. It's a very simple 3D shooter, but it gives an idea about A.I.

Sergio.


Kissme(Posted 2004) [#3]
Hi all,

@cash, i try to find a little sample code too :) i try to make a little demo. I using a terrain and i have 2 rabbits in, and i try to make rabbits moving if player it's around.

If someone have a little sample code, that's be great and i can make a donation around 50$ for ppl make a little and easy sample code.

Thanks
Stephanie

Kiss ya
Stephanie


semar(Posted 2004) [#4]
A simple A.I. pseudocode fo rabbits:
for rabbit.t_rabbit = each t_rabbit
if rabbit\status = S_IDLE then
if entitydistance(rabbit,player) < 10 then

   ;change rabbit status
   rabbit\status = S_MOVE

   ;generate a target pivot where the rabbit should move to
   x = entityx(rabbit\entity)
   z = entityz(rabbit\entity)
   rabbit\target = createpivot(x,z)

endif
endif

play_rabbit(rabbit)

next

function play_rabbit(rabbit.t_rabbit)
;move the rabbit until he reaches the target
if entitydistance(rabbit\entity,rabbit\target) > 10 then

   ;turn the rabbit toward the target
   pointentity(rabbit\entity,rabbit\target)

   ;move the rabbit on the z axis
   moveentity rabbit\entity,0,0,0.5
else
   ;reset the status
   rabbit\status = S_IDLE
endif
end function


Hope this helps...

Sergio.


Kissme(Posted 2004) [#5]
Woah ! Sergio, can i send u a email plz ?


semar(Posted 2004) [#6]
My e-mail is in my profile. However, bare in mind that if you need help in coding, this forum is the best place IMO.

Ah, and use your donation to feed some real rabbit...

;-)

Sergio.


Kissme(Posted 2004) [#7]
Oki :)


jfk EO-11110(Posted 2004) [#8]
I always used a state model. Normaly the guards are patroling, but when they see the player (using entityvisible if they are close enough, and maybe the Field of View Function from the code archives), then they go into panic mode. In panic mode their reaction time is shorter and their field of view is bigger. In panic Mode they also run instead of walking. I added some direct bones manipulation to the neck of the guards, so first (if not in panic mode) they look to the player, then it takes up to a second until they react, kind of "what the..!!!"-reaction.
When the player escapes successfully, they fall back into normal patroling mode (non-panic) after a couple of time, 20 secs or something.
It is also possible to allow chain reactions of panic-mode enabling. So if one guard has seen you, an other guard who cannot see you but can see the first guard is now in panic mode too. This can be solved recursively.


Techlord(Posted 2004) [#9]
cash,

This may be of some help heres my implementation of Bot AI for Project Plasma. This is work in progress, however, basic AI framework is place. Take a close look at the botSensor, botReaction, and botMotor.