Author Topic: Enemy Routing Tips?  (Read 3780 times)

0 Members and 1 Guest are viewing this topic.

Offline Derf321

  • LV3 Member (Next: 100)
  • ***
  • Posts: 59
  • Rating: +0/-0
    • View Profile
Enemy Routing Tips?
« on: October 11, 2012, 12:27:12 pm »
I'm having a dilemma trying to decide how to route the enemies in my game the best way. Right now they go straight toward the player, and will slide along walls if the player is diagonal from them (they will not go through walls). The problem is that if a player is directly on the other side of the wall (walls are red in the picture), the enemies will just stay against the wall, so I need to re-route them to go through the nearest doorway. What do you guys think the easiest way to do this would be?

(the player is the dot inside the walls, the enemies spawn outside)
« Last Edit: October 11, 2012, 12:27:55 pm by Derf321 »

Offline Stefan Bauwens

  • Creator of Myst 89 - סטיבן
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1799
  • Rating: +162/-24
  • 68k programmer
    • View Profile
    • Portfolio
Re: Enemy Routing Tips?
« Reply #1 on: October 11, 2012, 01:32:26 pm »
Perhaps you could check only to move towards the player when not touching a wall.
If you hit a wall then, you check the bots coordinates and door coordinates to see which door is closest. Then stop all other checks to go to the player and move towards the door entrance. Then with another check you see if you reached it, and if so then you continue moving towards the player.

Hope it may have helped.


Very proud Ticalc.org POTY winner (2011 68k) with Myst 89!
Very proud TI-Planet.org DBZ winner(2013)

Interview with me

Offline Xaychru04

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 9
  • Rating: +0/-0
    • View Profile
    • Xaychru04's blog
Re: Enemy Routing Tips?
« Reply #2 on: October 11, 2012, 02:22:41 pm »
I don't know how do you store your map but if you're using tilemapping, you can apply a pathfinding algorithm such as A*, it isn't very difficult, and here's a good tutorial: http://www.policyalmanac.org/games/aStarTutorial.htm.
If you're not using tilemapping, you could maybe apply this algorithm with an imaginary grid and test for each cell you want to test if the ennemy is on a wall at the location of this imaginary cell...
« Last Edit: October 11, 2012, 02:24:16 pm by Xaychru04 »