Hi, I’m trying to create a script that I use in some Attack...
but it doesn’t work well — whenever the character is close (<7 pixels), it keeps moving. It must move only if Oponent Body dist > 7 only this. I also put direction to prevent a bug if oponent run back
- If opponent is on the right → face right and move (+7)
- If on the left → face left and move (-7)
- If very close (between -7 and 7) → stop moving (do nothing)
Code:
@script
if(frame == 0)
{
void self = getlocalvar("self");
void opponent = getentityproperty(self, "opponent");
if(opponent)
{
float x = getentityproperty(self, "x");
float ox = getentityproperty(opponent, "x");
float dist = ox - x;
// Flip
if(dist > 0)
{
changeentityproperty(self, "direction", 1);
changeentityproperty(self, "velocity", 7, 0, 0);
}
else if(dist < 0)
{
changeentityproperty(self, "direction", 0);
changeentityproperty(self, "velocity", -7, 0, 0);
}
// if close
if(dist <= 7 && dist >= -7)
{
changeentityproperty(self, "velocity", 0, 0, 0);
}
}
}
@end_script
but it doesn’t work well — whenever the character is close (<7 pixels), it keeps moving. It must move only if Oponent Body dist > 7 only this. I also put direction to prevent a bug if oponent run back
