0

I'm trying to set up my enemies behaviors so that they will chase the player, while avoiding obstacles (walls and such) and stay sufficiently separated from one another (partial flocking). What I want is for the enemies to get in contact with the player without overlapping one another. If I set my seek goal higher than the separate goal that's exactly what happens: enemies will chase the player but will also overlap perfectly to the point you won't be able to distinguish them. If I set my separate goal higher than the chase goal, they will chase the player and stay separated all the while but once they have reached him they'll just spin around their position instead of keep going for him.

Any tips? Here's my code (I'm not using align and cohere rules right now):

let enemyGoals = GKBehavior(goals: [
  alignGoal,
  cohereGoal,
  separateGoal,
  chaseGoal,
  avoidGoal
]);

// enemyGoals.setWeight(90, for: chaseGoal);
// enemyGoals.setWeight(95, for: avoidGoal);
enemyGoals.setWeight(100, for: separateGoal);

enemyHead.agent.behavior = enemyGoals;
agentSystem.addComponent(enemyHead.agent);
Uplink001
  • 71
  • 5
  • Do they have physics bodies? I suppose you could ditch the separate goal altogether and just let the physics engine not allow them to overlap. – Dennis Mar 15 '18 at 21:51
  • Exactly what I was thinking but I must say: I'd rather not resort to that, I already have a whole lot of physics bodies due to the fact that my world is tile based and I had to include some sort of walls so I already have enough of those. – Uplink001 Mar 16 '18 at 00:05

0 Answers0