Its me again :> This time i want to create a knockback on collision with an enemy entity. (After 5 collisions the player entity get removed) To accomplish this i tried it this way
protected var knock:Boolean = false;
override public function update():void
{
super.update();
knockingBack();
if (collideTypes(["schatten"], x, y))
{
trace("contact");
knock = true;
}
}
private function knockingBack():void
{
var k:uint = 4;
if (knock = true)
{
if ((lastRichtung = "Nord") && (k != 0))
{
y += Geschwind +100 / 2;
k--;
}
else if ((lastRichtung = "Sud") && (k != 0))
{
y -= Geschwind +100 / 2;
k--;
}
else if ((lastRichtung = "West") && (k != 0))
{
x += Geschwind +100 / 2;
k--;
}
else if ((lastRichtung = "Ost") && (k != 0))
{
x -= Geschwind +100 / 2;
k--;
}
else if (k == 0)
{
knock = false;
}
}
}
But this leads to my player falling out of the window. can you find the problem?