Hello again.
Im trying to make an effect on my hero’s melee attack. Like when he hits the enemy, the enemy is thrown a bit away.
Im trying this stuff with while, but i also tried with other things and it didnt work.
Here is the code:
public function knifeCollision(event:Event):void
{
var distance:Number=Math.sqrt( ( this.x - _r.circle.x ) * ( this.x - _r.circle.x ) + ( this.y - _r.circle.y ) * ( this.y - _r.circle.y ) );
enemyHP=enemyHealth;
enemyDeath=false;
if(enemyHP>0)
{
if(_r.circle.circleknife.knife.hitTestObject(this))
{
this.y-=30;
enemyHealth-=1/2;
this.gotoAndStop(5);
if(this.x>_r.circle.x)
{
while(distance<200)
{
this.x+=10;
}
}
else if(this.x<_r.circle.x)
{
while(distance<200)
{
this.x-=10;
}
}
}
}
else if(enemyHP<=0)
{
enemyDeath=true;
if(enemyDeath==true)
{
gotoAndStop(4);
removeEventListener(Event.ENTER_FRAME, eFrame);
}
}
}
The problem is that when i hit CTRL-ENTER with this code and i melee the enemy the whole program blocks.
I also tried puting like a coordinate instead of distance, like this:
while(this.x<800)
{
this.x+=10;
}
Its not good for a game but i jsut tried to see what happens, and when i hit with melee it will jsut teleport the enemy to x=800.
I just want the enemy to smoothly be thrown to the coordinate like with speed 10.
I also do it on Y axis after i figure the X axis.
Also tried
do
{
this.x+=10;
}
while (distance<200)
I would appreciate any help on this matter.