• 15
• 15
• 11
• 9
• 10

# NPC Collision Detection

This topic is 3990 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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


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?

##### Share on other sites
For this kind of thing is would probably be best to use pathfinding.

There is some decent info on the subject here

Regards,
ViLiO