Okay, you could set up a distance check, it really depends on how mobile you want the enemies and how you are going to have them attack. Will the enemies shoot you too, or will they just rush attack you? As far as other methods, one way talked about in one of the demos is using paths, though I avoid those as they are not very editable. Moving back in forth would be really easy with timers, but I don't mean the gameEditor timers. I am talking about a variable that increments every frame. And depending on what it is, the enemy will move either left or right.
Enemy->DrawActor->Script Editor
- Code: Select all
if (count>0)
{
count++;
}
switch(count)
{
case 1:
//ChangeAnimation to left
xvelocity=-5;
break;
case 100:
//ChangeAnimation to right
xvelocity=5;
count=1;
break;
case 101:
//Attack
break;
}
Note that you need to initialize the enemy, on create actor, count equals one. If the enemy's horizontal distance is under a certain range, you can switch count to 101 to initialize the attack, and have that repeat.