Jump to content
  • Advertisement
Sign in to follow this  
touches

[AS2 Flash] Enemy-AI movement and collision

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

If you intended to correct an error in the post then please contact us.

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
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!