Alright, so I finally have some time to respond to this.
Using a second hitbox is a good start, but the problem of course is that you can’t test collisions on specific masks that have been added to your entity with a Masklist. The approach I’d recommend in this case is to use a “sub-entity” with a separate hitbox and use that for detection.
Here’s a bare-bones example:
private var detection:Entity;
public function Enemy()
{
// other stuff
detection = new Entity();
detection.width = 100;
detection.height = 50;
detection.centerOrigin();
}
override public function added():void
{
world.add(detection);
}
override public function removed():void
{
world.remove(detection);
}
You can now check for visibility like this:
if (detection.collide("Player", x - detection.halfWidth, y))
{
// jump left
}
if (detection.collide("Player", x + detection.halfWidth, y))
{
// jump right
}
You’ll want to do some other checks too; for example a call to world.collideLine()
would help you find out if there’s a wall between the enemy and the player, but that’s the basic method I used recently.