Sign in to follow this  
touches

[AS2 Flash] Enemy-AI movement and collision

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???

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this