S
Shariku Onikage
Guest
I'm trying to create an enemy patrol route with multiple states (wandering, alerted, chasing, searching, returning to start point and wandering again). Wandering, detecting the player and chasing him appear to work fine, but when the enemy object tries to run to the player's last known point, the object behaves erratically, flickering on the spot and not moving in any direction (as if speed was zero and direction was constantly switching +180 degrees each time).
My code is below. I get the feeling that it's the lastKnownPositionX and lastKnownPositionY that's causing the issues. Can anyone help in seeing any obvious mistakes that i've made?
Thanks in advance.
oEnemy object - Step:
My code is below. I get the feeling that it's the lastKnownPositionX and lastKnownPositionY that's causing the issues. Can anyone help in seeing any obvious mistakes that i've made?
Thanks in advance.
oEnemy object - Step:
Code:
if status = "Wander" {
speed = patrolSpeed;
testForAlert(); //test to see if enemy can see player, works as expected
} else if status = "Alert" {
if ableToSee(oPlayer) { //if still able to see player, will run towards player, works as expected
speed = chaseSpeed;
direction = point_direction(x,y,oPlayer.x,oPlayer.y);
} else { //will stop running towards player
lastKnownPositionX = oPlayer.x;
lastKnownPositionY = oPlayer.y; //notes the x and y of the last spot the player was seen by the enemy, testing shows that this gets noted down kind of as expected (e.g. x = 120.45)
status = "RuntoLastPoint"; //no longer chasing player, now trying to find player
doIActivate=1000; //for testing, yes it does
}
}
if status = "RuntoLastPoint" {
testForAlert(); //test to see if enemy can see player
if (x ==lastKnownPositionX && y ==lastKnownPositionY) {
status = "Searching";
doIActivate=1; //for testing, can't tell if this works as it switches to 2 too quickly
} else {
alarm[2]=room_speed*2; //will switch status to "Searching" if unable to reach player's last point in two seconds, this doesn't appear to happen
speed = chaseSpeed;
direction = point_direction(x,y,lastKnownPositionX,lastKnownPositionY); //run towards the last point the player was seen at - this doesn't happen, the enemy object just shakes on the spot instead
doIActivate=2; //for testing, yes it does, and it stays there too
}
}