Im trying to use hitTestPoint to detect if a enemy has hit a wall. I have the code working for the player, which is located on the main stage (the player doesn’t move, the map scrolls). The map, with the enemies is located in a MC - mainmap. mainmap contains walls MC and an instance of enemy. I can’t seem to get the code to work for the enemy’s hitTest. Any ideas to where Im going wrong? Maybe this is the wrong method to use.
SWF:
http://www.swfcabin.com/open/1276151501
Code on the enemy:
for (var i:int = 0; i < thisParent.walls.numChildren; i++) {
var obj:MovieClip=thisParent.walls.getChildAt(i) as MovieClip;
if (obj.hitTestPoint(this.x+35,this.y)) {
this.x-=enemySpeed;
}
if (obj.hitTestPoint(this.x-35,this.y)) {
this.x+=enemySpeed;
}
if (obj.hitTestPoint(this.x,this.y+40)) {
this.y-=enemySpeed; }
if (obj.hitTestPoint(this.x,this.y-40)) {
this.y+=enemySpeed;
}
}
Any help would be great!