<SOLVED>Enemy Search Random

Hi guys! I’m trying to make an enemy that would search randomly around the map for the player how everytime he reaches his destination earlier than the timer he sticks around at the location and sort of jiggles until a new position is decided. Can anyone give me tips on a better random search ai for the enemy? Thanks!

I’ll assume you are using Patchfinding or something like it

  1. If timer “SearchTimer” Enemy > 1.000 OR Enemy::Pathfinding has reached destination then Pick a nearby random locationand move to it:
    Move Enemy to (RandomInRange(Enemy.X() - 100, Enemy.X() + 100, RandomInRange(Enemy.Y() - 100, Enemy.Y() + 100)
  2. Emulate a view cone to chase the player if seen: If (abs(Enemy.AngleTo(Player) - Enemy.Angle()) < 30) and (Enemy.DistanceTo(Player) < 500) then Move Enemy to (Player.X(), Player.Y())
  3. You probably want to add multiple distance conditionals to that last part because presumably if the enemy is really close to the player it should attack. You’ll probably want to increase the speed of the Enemy if it “spots” the player.
1 Like

Thank you very much! I never knew that there is something called pathfinding I was just moving the enemy to a randomized x and randomized y now I have an idea of how to proceed.