2
\$\begingroup\$

I'm developing a top-down game in XNA with enemies that wander until they are within range of a player, at which point they begin chasing the player. This works, but I also want them to avoid obstacles around the map while chasing.

I can find tutorials on programming the avoidance behavior, but I'm unsure as how to integrate that into my current AI so that the enemy both chases the players while also avoiding obstacles. I cannot use a pathfinding algorithm like A* because my current AI is steering-based.

How should I go about integrating this?

\$\endgroup\$
4
\$\begingroup\$

Since your AI is steering based it's pretty simple. You need to weigh your forces based on how important they are. The closer you get to obstacles the more important they should be, otherwise chasing should be the most important. There are a couple different ways to implement it, but I always found having some "max force" worked best where you iterate over your steering behaviors, calculate the force (which is scaled by a weight based on importance), and add the force to a total vector. Don't let the magnitude of the total vector exceed "max force". Ordering of behaviors & momentary importance decides how your AI behaves.

| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

If you've been looking at steering behaviours you've probably seen this page which is by the guy who first came up with steering behaviours. If you want to know about the general background of how steering behaviours work that's the best place to start.

The steering behaviours were implemented by the same chap in a library called OpenSteer which was ported to C# and then fixed for XNA4 and finally I have forked the library for my own game.

tl;dr: You can find my XNA4 compatible library implementing all the Steering behaviours. I suggest you download the library and check out the Demo Application to see how to use behaviours. If you decide you want to use it, there's a nuget package available.

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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