Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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

share|improve this question
1  
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? –  Luis Estrada Dec 29 '12 at 0:43
    
bonus = enemy sprite you try to catch –  user300675 Dec 29 '12 at 2:01
1  
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?) –  Trevor Powell Dec 29 '12 at 2:18
    
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? –  Aufziehvogel Dec 29 '12 at 9:42
    
infact a bonus is an enemy that you need to catch –  user300675 Dec 29 '12 at 14:16

1 Answer 1

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.