I'm using flash CC for school and i am making a top down RPG which i am making using action script 3. the problem that i am having is multi layered; i need the AI i made to detect the set boundaries, and i need them to change direction when they hit these boundaries. at the moment i have used trace functions to find out when the AI is hitting the boundaries, so i know that that is working. however then it doesn't run the code after that. the map at the moment is a maze so the barriers are a movie clip that have rectangles going over the walls within the maze. it works for the player that the user controls so why won't it work here? below is the code for the AI movement:
switch (guyFacing) { // which way the AI has turned (left, right, up, down) (this is randomly generated below
case 0:
OverworldMC.guyMC.gotoAndStop("walk back frame");
OverworldMC.guyMC.y -= guySpeed;
break;
case 1:
OverworldMC.guyMC.gotoAndStop("walk front frame");
OverworldMC.guyMC.y += guySpeed;
break;
case 2:
OverworldMC.guyMC.gotoAndStop("walk left frame");
OverworldMC.guyMC.x -= guySpeed;
break;
case 3:
OverworldMC.guyMC.gotoAndStop("walk right frame");
OverworldMC.guyMC.x += guySpeed;
break;
}
guyTimer++; //duration that the AI is moving around the screen
} else {
guyWalkDur = Math.random() * 75;
guyFacing = Math.floor(Math.random() * 4);
guyTimer = 0;
}
}
if (OverworldMC.collisionMC.hitTestPoint(OverworldMC.guyMC.x + GleftBumpPoint.x, OverworldMC.guyMC.y + GleftBumpPoint.y, true)) {
trace("GleftBumping");
GleftBumping = true;
} else {
GleftBumping = false;
}
if (OverworldMC.collisionMC.hitTestPoint(OverworldMC.guyMC.x + GrightBumpPoint.x, OverworldMC.guyMC.y + GrightBumpPoint.y, true)) {
trace("GrightBumping");
GrightBumping = true;
} else {
GrightBumping = false;
}
if (OverworldMC.collisionMC.hitTestPoint(OverworldMC.guyMC.x + GupBumpPoint.x, OverworldMC.guyMC.y + GupBumpPoint.y, true)) {
trace("GupBumping");
GupBumping = true;
} else {
GupBumping = false;
}
if (OverworldMC.collisionMC.hitTestPoint(OverworldMC.guyMC.x + GdownBumpPoint.x, OverworldMC.guyMC.y + GdownBumpPoint.y, true)) {
trace("GdownBumping");
GdownBumping = true;
} else {
GdownBumping = false;
}
if (GleftBumping) {
OverworldMC.guyMC.gotoAndStop("walk right frame");
OverworldMC.guyMC.x -= guySpeed;
trace("hitting is true");
}
if (GrightBumping) {
OverworldMC.guyMC.gotoAndStop("walk left frame");
OverworldMC.guyMC.x += guySpeed;
}
if (GupBumping) {
OverworldMC.guyMC.gotoAndStop("walk front frame");
OverworldMC.guyMC.y -= guySpeed;
}
if (GdownBumping) {
OverworldMC.guyMC.gotoAndStop("walk back frame");
OverworldMC.guyMC.y += guySpeed;
}
The aim of this code is to randomly generate an action (which it does), detect when it is hitting the barrier and then act according to how it is interacting with the barrier only i am having some trouble with the last part. Any and all help is appreciated. Regards.