# [AS2 Flash] Enemy-AI movement and collision

This topic is 3210 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

hello all i am trying to create a simple game in flash 8... I have created a player,enemy and walls... i have implemented a very very basic chasing algo to the enemy... Now whenever there are obstacles the NPC gets stuck in them. I want to make my enemy movement more intelligent and i want to improve my enemy's collisions.. Can any1 point me on how to make the enemy more intelligent in his movement.. I refered some of the AI books but i cud not understand them as some of the books calculated pixel values .. Could any1 explain in terms of AS2.. Help wud be grateful... well this is the code for NPC's movement and for collisions
ai.onEnterFrame=function(){
follow();
}
function follow(){

if(ai._x<lupin_mc._x){
ai._x+=3;
}
if(ai._x>lupin_mc._x){
ai._x-=3;
}
if(ai._y<lupin_mc._y){
ai._y+=3;
}
if(ai._y>lupin_mc._y){
ai._y-=3;
}
while (_root.wall_mc.hitTest(ai._x, ai._y+22, true)) {
ai._y-=7;
}
while (_root.wall_mc.hitTest(ai._x, ai._y-12, true)) {
ai._y+=7;
}
while (_root.wall_mc.hitTest(ai._x-3, ai._y, true)) {
ai._x+=4;
}
while (_root.wall_mc.hitTest(ai._x+44, ai._y, true)) {
ai._x-=4;
}

}
// The wall is typically like a maze eg: like in pac-man but i am not using tiles


I know this is very basic but i cud not find any tutorials that teaches avoiding obstacles for the NPC in flash.. Is there any way i can attach my file coz i cud not find an option???

1. 1
2. 2
Rutin
19
3. 3
khawk
19
4. 4
5. 5
A4L
11

• 9
• 12
• 16
• 26
• 10
• ### Forum Statistics

• Total Topics
633771
• Total Posts
3013761
×