NPC Collision Detection

Started by
1 comment, last by Butterman 16 years, 12 months ago
Hey. Ive got aggressive NPCs that attack the player if the player comes within a certain square around the NPC (Once the NPC has "seen" the player it will chase him forever). It then follows the player. It finds on which axis the player is further away (X or Y) and move in that direction. (I didnt want them moving diagonnally) This all works fine. But the problem comes when the NPC is on another side of an un-passable object. The NPC walks right through it. Ive tried getting around this by stopping the NPC on a collision. Then making it decide which direction to go from the position of the player. But i have not been able to get even this to work. For example

      
      X (Player is closer on the right. So go right until you can go down)
  =======

       P

P = Player
X = Baddie



But this wont work where

  |======
  |      
  |  X   
  |=======
   Y

The NPC will just go left into the wall and will get stuck.



Note that information is storred in tile maps. What do you suggest?
Game Development Tutorials, a few good game development tutorials located on my site.
Advertisement
For this kind of thing is would probably be best to use pathfinding.

There is some decent info on the subject here

Regards,
ViLiO
Richard 'ViLiO' Thomasv.net | Twitter | YouTube
Movements arent done tile by tile. But pixel by pixel. So would using the same algorithm for pixel by pixel work? Or would it be a big slow down?
Game Development Tutorials, a few good game development tutorials located on my site.

This topic is closed to new replies.

Advertisement