View Full Version : [AS2] How to make a enemy following me?
arashmalek
12-26-2008, 07:16 PM
Hello!
Is it some one who know the code to make a enemy following the character in a game?
Bod720
12-27-2008, 04:50 PM
http://www.kirupa.com/developer/mx/followease.htm
But change the _xmouse to character_mc._x and the same with the y value.
orange gold
12-28-2008, 06:43 AM
you might also want to change the speed from 5 to something like 0.2 or maybe even lower.. this will work for basic but once you have walls you will have to either make it walk through walls or for each wall name detect which way the monster will have to go to get around and do a hit test and send it moving to the left or right or up or down or whatever it needs to get around
pradvan
12-30-2008, 05:24 PM
Here's another follow player script. This one is a bit more advanced than what Bod posted:
http://www.freeactionscript.com/2008/10/game-enemy-ai-follow-player/
orange gold
12-30-2008, 07:10 PM
it looks to me like you would want to combine thats ones distance code with the other ones stopping and speed codes to get what your trying to achieve
arashmalek
01-02-2009, 03:49 PM
Thank you Bod720, the link helpt me. :)
arashmalek
01-02-2009, 04:05 PM
But the enemy move fast in the begining and when it is close to the character it moves slower. It would be better if it had the same speed whole time. Do you know how to fix that? I gone watch the other link to :p
Bod720
01-02-2009, 08:36 PM
I think
_x += endX/speed;
_y += endY/speed;
would work
arashmalek
01-02-2009, 11:39 PM
It dont work for me, it just make the enemy move toward where tha character started.
Bod720
01-03-2009, 12:50 AM
Hi. Can you upload an .fla of just your character following bit, and I'll fiddle with the code to get it working. Thanks.
arashmalek
01-03-2009, 01:23 AM
yes of course.
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.