2
\$\begingroup\$

I would like to know what is the best way to implement collision avoidance and eventually pathfinding in a LibGDX 2D top view game. Think of "Binding of Isaac".

I use a sort of tilemap to place the obstacles (squares), taken from an ASCII map, but I'd prefer to keep the movements free from it. (Enemies shouldn't move from tile to tile but freely)

Since the target is mobile I can't use heavy algorithms.

I'm not particularly concearned about enemies getting stuck on weird shapes (such as 'U') since it kind of makes sense (they are white globules, not particularly smart :P) but I still want them to be a challenge.

I've taken into consideration Steering Behaviors and the LibGDX-AI framework but I can't find good documentation, I can aswell code it by myself in case.

ANOTHER QUESTION Just to know, which kind of algorithm is used in the Binding of Isaac? It perfectly suits my needs

\$\endgroup\$
1
\$\begingroup\$

For path finding, A* (pronounced a star) ought to fit your situation real nice (for people who don't know what binding of Isaac is, it's basically the original legend of Zelda).

For avoidance, I can't think of any named algorithms, but I think it will basically be pretty simple to code up some heuristics (rules) to where if an enemy is in the path of a projectile that can hurt it, it just moves out of the way. Similar for if the player starts getting into melee range or whatever else.

It will probably take some iteration on the heuristics you come up with for each enemy type, to get the exact behaviors you want, as well as making sure they are not too easy or too difficult to fight (:

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Yup ^^. I would like an hint towards an algorithm (keeping in mind that I have an Array of all the obstacles' position). I can think of many solutions but since it's going to be the heaviest part of my game I'd prefer to know what is the best solution and avoid reinventing the wheel :P \$\endgroup\$ – Fiochkij Jun 28 '15 at 10:26
  • \$\begingroup\$ How many enemies do you have at one time? The game you mention looks like 10 max. If that's your size too, you just need to get coding! PS if you have far too many enemies to run ai logic each frame you can just run logic for a few enemies every frame. But yeah, when I say I can't think of a specifically named algorithm its because people generally write "one off" ad hoc code for ai behavior. There is no magic bullet single solution (: \$\endgroup\$ – Alan Wolfe Jun 28 '15 at 13:10
  • \$\begingroup\$ Oh sorry. You might actually want to check out state machines for ai behavior. Basically, an enemy has a current state such as "running away", "chasing player" or "resting in one spot". You program the logic for each state and have rules about when and how an enemy can transition from one state to another. State machines are actually a common algorithm for AI behavior. \$\endgroup\$ – Alan Wolfe Jun 28 '15 at 13:17
  • \$\begingroup\$ I'm going to have around 5-6 enemies at time, the max number I can think of is 20 or so and yes, I can schedule their computations if needed. I'm already thinking about coding my own solution but since I have no practical experience I'd like to know if there are "better ways" for this kind of things. For example, is raycasting better than a navigation mesh? Creating the navmesh can be expensive but since all my obstacles are squares and I have an ASCII map maybe I can make it way easier. Also, is it better to check the collision on the "rendered map" using rays or check the ASCII one? \$\endgroup\$ – Fiochkij Jun 28 '15 at 13:21
  • \$\begingroup\$ If you want my opinion, you ought to just do A* path finding on a grid, not make a navmesh (it's overkill!). Ray casts on your map grid makes sense for line of sight tests, as part of what would drive your ai behaviors. Check out this link about using state machines for ai behavior, might be helpful: gamedevelopment.tutsplus.com/tutorials/… \$\endgroup\$ – Alan Wolfe Jun 28 '15 at 13:26

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