# Need help with wall avoidance

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

## Recommended Posts

Hi I am currently develoing an AI enemy that walks around randomly in my level but now I need for him to avoid walking in to walls how do I do this? I am using directx and would appreciate all the help I can get [Edited by - Andreas Persson on January 1, 2006 10:33:48 AM]

##### Share on other sites
By using some kind of path finding algorithm. There are various algorithms around that are better suited to certain situations.

If your level is 3D and not based around tiles then a good method might be to add hidden entities to the level and use them as waypoints for the A.I. so that it can find its way around obstacles and walls etc.

If your level is tile based then an algorithm like A* might be better suited to the situation.

A quick search on google (or maybe even in the articles on gamedev) should find you plenty of examples of path finding algorithms. I have written an implementation of the A* algorithm in C++ if you would like to take a look at it.

Edit: also calling your thread "Need help" is frowned upon, try to use a descriptive title to do with the content of your thread.

##### Share on other sites
Yes I have looked at A* but I was more after some form of separation from the walls, let´s say that an enemy is wandering randomly in my world and he is heading towards a wall I want him to "feel" the wall and turn in another direction when he gets to close.

And thanks for the tip I changed it

##### Share on other sites
How about having a vector from the centre of your enemy, have its length equal to the minimum distance between your enemy and the walls/obstacles in the level, and have the direction the same as the enemy's direction. As your enemy is moving around the level you could check to see if this vector touches or goes through the walls in the level. If it does then turn both the enemy and the vector until there is some free space for movement.

##### Share on other sites
Hm sounds like a good idea I´ll try it out thanks :)

##### Share on other sites
If you still need help, in a book I read the author projects 3 "feelers" out in front of the agent, one straight ahead, then at 45 degree angles to either side.
then, using a physics system he already had set up, he put a force on the agent in the direction perpendicular to the wall. the strength of the force was directly proportional to the distance the "feeler" had penetrated the wall, it works pretty good.
Hope this helps.
Svenjamin

I forgot, the length of the feelers is directly proportional to the agent's current velocity.

1. 1
Rutin
47
2. 2
3. 3
4. 4
5. 5

• 13
• 10
• 12
• 10
• 13
• ### Forum Statistics

• Total Topics
632994
• Total Posts
3009769
• ### Who's Online (See full list)

There are no registered users currently online

×