It will take 3 parameters:
1st param: &YourActorName
2nd param: Distance monster will notice you from. (int number)
3rd param: Distance monster will actively pursue you.(int number)
Place the following code in global code.
- Code: Select all
int monsterpursuit(Actor *ActiveMonster,int Msees,int Mattacks)
{
int enemyrange;
int seednumber;
int multiplier;
int approachangle;
enemyrange=distance(player.x,player.y,ActiveMonster->x,ActiveMonster->y);
approachangle=(direction(ActiveMonster->x, ActiveMonster->y, player.x, player.y)/10);
//enemy scans area
if(enemyrange>Msees-1){
ChangeAnimationDirection(ActiveMonster->name, FORWARD);
}
//enemy notices player
if( enemyrange<Msees && enemyrange>Mattacks)
{
ActiveMonster->animpos=approachangle;
}
if(enemyrange<Mattacks+1 && enemyrange>0)
{
ActiveMonster->animpos=approachangle;
ActiveMonster->directional_velocity=(seednumber/enemyrange)*multiplier;
MoveTo(ActiveMonster->name, 0.000000, 0.000000, ActiveMonster->directional_velocity, "player", "");
}
return enemyrange;
}
approachangle is used to set Actors animation for a 36 frame animation with frame 0 looking east.
Then, in your monster/enemy's DrawActor event, place a call to it like this:
Example using Actor: BigMonster who will see you at a distance of 300 units and attack at 150units. It will return an integer of Distance from player.
- Code: Select all
DistanceFrom=monsterpursuit(&BigMonster,300,150);