# Bad Guy Teleports

**URL:** <https://forum.kirupa.com/t/bad-guy-teleports/309976>\
**Category:** Uncategorized\
**Created:** [May 28, 2010, 9:28pm UTC](https://forum.kirupa.com/t/bad-guy-teleports/309976 "2010-05-28T21:28:27Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![noisavni](https://avatars.discourse-cdn.com/v4/letter/n/b487fb/32.png) [@noisavni](https://forum.kirupa.com/u/noisavni)\
**Post date:** [May 28, 2010, 9:28pm UTC](https://forum.kirupa.com/t/bad-guy-teleports/309976/1 "2010-05-28T21:28:27Z")

</div>

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:

```auto
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:

```auto
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

```auto
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?
