Skip to main content
GameDev.net gamedev.net
🔒 Locked

flash enemy AI

Started by h3dg3h0g Jan 21, 2006 at 12:58 PM 0 replies 1.1k views
Original Post
h3dg3h0g
h3dg3h0g
So far i have created an enemy and a character for an RPG game The enemy is randomly walking, and palys teh correct animation for each of the four directions The enemy has a range, if the character enters this range it will do SOMETHING This SOMETHING however i do not know how to do.... I want the enemy to WALK towards the charcter in a way similar to the way i have developed the rest of the code and animation ... Once the character walks outside of the range again, it will randomly walk again. Could someone please please help me, cos this has got very frustrating over the past couple of days, and im out of ideas... If the code below is not enuf for oyu to help ----------------------------------------------- The code below is applied to the movieclip, "enemy" the SOMETHING i want it to do is the area of question marks onClipEvent (load) { lock = true; up = 1; down = 2; right = 3; left = 4; speed = 4; none = 0; dir = random(4)+1; // initial direction off = true; damage = 0; all = true; function checkproximity() { // check proxymity dist_hero = 120; // check distance dx = _x-_root.hero._x; dy = _y-_root.hero._y; dist = Math.sqrt(dx*dx+dy*dy); // increase speed // check if hero dist is < 100 if (dist<dist_hero) { in_range = true; } else { in_range = false; lock = true; speed = 2; } } function follow() { if (in_range) { // if in range follow if (this.hitTest(_root.hero.hit)) { xstep = _root.hero.xstep; ystep = _root.hero.ystep; } lock = false; ????????? ????????? ????????? ????????? ????????? ????????? ????????? ????????? ????????? ????????? } } }
shadowcode
shadowcode
Build a FSM to which you can fire events.
(Look up Finite State Machine).

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.