I need some clues on a "escape" algorithm. My scene a 2D rectangle (0,0,1000,1000)

I have enemy sprites on this scene. They are immobile until distance from hero <100. If distance<100, enemy tries to escape from here, so hero tries to chase it.

When distance>100, enemy has escaped and becomes immobile again. The rule is of course that enemy cannot go outside the scene. And a enemy cannot overflow enemy bonus.

Any clues ? Regards

  • 1
    \$\begingroup\$ What is bonus? and what do you mean by a bonus cannot overflow another bonus? Can no two bonuses be next to each other? Also, does the 'bonus' have a speed? \$\endgroup\$ Dec 29 '12 at 0:43
  • \$\begingroup\$ bonus = enemy sprite you try to catch \$\endgroup\$
    – yarek
    Dec 29 '12 at 2:01
  • 1
    \$\begingroup\$ What's the problem? This seems like a pretty simple and straight-forward set of rules. Is this a "teach me to program" question? (I mean, are you asking for someone to explain "if/else" conditionals to you? Or what?) \$\endgroup\$ Dec 29 '12 at 2:18
  • \$\begingroup\$ I still do not understand what enemy bonus shall be. Neither do I understand what clues you need? Maybe something like: Calculate the direction to escape? \$\endgroup\$ Dec 29 '12 at 9:42
  • \$\begingroup\$ infact a bonus is an enemy that you need to catch \$\endgroup\$
    – yarek
    Dec 29 '12 at 14:16

I suggest you took a look at steering behaviors, which can provide a lot of simple but very flexible ways to control how actors respond to other actors on the map.

In particular, on that link, flee and evasion are good behaviors to look into. Their goal is to cause an enemy to either move away from the position and direction of the player, or to even try to avoid the future position of the player (so they don't act like a certain idiot in Prometheus).

In order to ensure that the enemies do not get stuck in the corners of your map, you can also add in the obstacle avoidance behavior, which will push the enemies away from walls as they close in.

I'm also unsure of what you mean by "overflow the enemy bonus," but it sounds from your comments (please update your question to clarify!) that the bonus is an enemy the player is meant to catch, and by overflow possibly you mean that you don't want fleeing enemies to sit on top of that enemy. You can handle this with the separation steering behavior, which incidentally is a good one to know since it's a part of the common and quite popular flocking algorithm.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .