[AS2 Flash] Enemy-AI movement and collision

Started by
-1 comments, last by touches 14 years, 1 month ago
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???

This topic is closed to new replies.

Advertisement