Alright, so there’s this bad guy and he’s an angry square:block: that follows the player on stage but when he comes in contact with the player instead of exploding like the rest of the baddies, he teleports millions of pixels off stage… I’m struggling to find where this is happening.
Here’s the trace:
x381.2 y203.95
x378.05 y207.85
x374.85 y211.7
x371.9 y215.75
x369.1 y219.9
x-107374181.4 y-107374181.4
x-107374176.85 y-107374176.85
x-107374172.3 y-107374172.3
x-107374167.75 y-107374167.75
Here’s the baddie movement:
public function moveGuy():void{
//move towards direction
this.x += Math.sin(Math.PI/180*this.rotation)*speed;
this.y += Math.cos(Math.PI/180*this.rotation)*(speed * -1);
}
public function checkHit(px, py):void{
//bounce from wall and change direction
if(this.x < 20 || this.x > 540 || this.y < 20 || this.y > 380){
if(this.x<20){this.x++;}if(this.x>540){this.x--;}
if(this.y<20){this.y++;}if(this.y>380){this.y--;}
this.rotation += 180;
}
//rotate towards player.x and .y
var theX:int = px+19 - (this.x);
var theY:int = (py+19 - (this.y)) * -1;
var angle = Math.atan(theY/theX)/(Math.PI/180);
if (theX<0) {
angle += 180;
}
if (theX>=0 && theY<0) {
angle += 360;
}
this.rotation = (angle*-1) + 90;
trace("x"+this.x+" "+"y"+this.y);
}
Here’s the collision detection for player/guy
function guyHitTest():void{
if(Vars.guyArray.length>0){
for(var i:Number = 0; i<Vars.guyArray.length; i++){
var guy:MovieClip = Vars.guyArray*;
var i**** = Collision.Basic(guy,player);
if(i**** && !playerProtected){
player.explode(player.x,player.y);
playerProtected = true;
guy.health--;
Vars.playerHealth--;
setArmor();
playerHitTimer.start();
player.alpha = .80;
playerHitTimer.addEventListener(TimerEvent.TIMER, removeProtection);
if(guy.checkHealth()){
guy.visible = false;
guy.explode(guy.x,guy.y);
guy.death();
Vars.guyArray.splice(i,1);
}
}
}
}
}
Any ideas on what’s teleporting the bad guy?