Hello guys.So i have a enemy that walks around.When he see player from a however range he should jump and run after him.The game is a platformer. Also there can be walls or other things that will not let enemy see the player(doesn’t mather if player is in his sight range) What i was thinking to do is something like this: Because this entity has 2 hitboxes,and the other hitbox is a entity that just follow the enemy i thought of this:
public function iSeePlayer():void
{
if (myParent.whatDo == "stay" || myParent.whatDo == "think" || myParent.whatDo == "walk") {
var counter:int = 1;
var myWidth:int;
var collideWith:Array = ["solid", "crate", "powerDoor", "Door", "player"];
collidedSomething = false;
saveX = x;
saveY = y;
if (myParent.flippedImg) {
myWidth = 22;
}
else {
myWidth = -22;
}
while (!collidedSomething && counter <= 4) {
moveBy(myWidth, 0, collideWith, true);
}
x = saveX;
y = saveY;
}
}
override public function moveCollideX(e:Entity):Boolean
{
collidedSomething = true;
if (e.type == "player") {
//make my parent run
}
return true;
}
I feel like this is a bit ineficient so im asking you guys if you know a more efficient way of doing this.Thx