Jump to content
  • Advertisement
Sign in to follow this  
howie_007

bot chasing the player problem

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

My map is an indoor map. It's an office building so it's hallways and rooms. I have my path nodes at the intersections of the hallway as well as the doorways leading into the rooms. As the player moves around the map, the player class records the closest path node and the bot uses that to find the player. The problem happens when the bot reaches the node the player is assumed to be at. Because of the distance between nodes, the bot doesn't know where to go because the player is close enough to the recorded node but too far from the bot for it to attack. So I need to figure out a way for the code to determine if the player position is in-between the current node and the next node or the current node and the previous node. That way the bot will move to the node in the players direction. any thoughts?

Share this post


Link to post
Share on other sites
Advertisement
Firstly, make sure that all possible points in your world are within attack range of a node. Once you've done that, your problem goes away. That is, if the bot is moving A to B and the player is between A and B, but closer to B, then the bot should enter an attack mode once the player is in range before reaching node B. If the player is between B and C, then the change to attack state won't trigger until after the bot has reached B.

Skizz

Share this post


Link to post
Share on other sites
I agree with your suggestion but I was hoping for a code solution instead of adding a ton more path nodes. There may be situations in which more path nodes cause different problems. If I can tell if a posistion is in-between two nodes, that would work.

Share this post


Link to post
Share on other sites
Create a line AB. Create a perpendicular line that passes through B, call it ABperp. Determine which side of this line the target is on.

Skizz

Share this post


Link to post
Share on other sites
I was thinking about this on my bicycle on the way into work this morning (it's where I have all my best ideas!). It turns out that to determine which side of the perpendicular line the player is on, do:

AB dot BP

where AB is the vector from node A to node B and BP is the vector from node B to the player. If the result of that dot product is < 0 then the player is between A and B, if it's > 0 the player is on the other side of B.

Skizz

Share this post


Link to post
Share on other sites
The solution that keeps on giving.

Getting the dot product between two vectors solved yet another problem I had.

The problem was the player could have run past the bot in the opposite direction the bot was traveling. As the bot travels from node a to node b, it encounter the player. If the player runs around the bot towards a, the nodes need to be switch because the bot needs to turnaround and move in the other direction.

cool. Weeeeee.

Share this post


Link to post
Share on other sites
Glad to help.

If your bots have the freedom to point in many directions, you can use the following to determine which way the bot should turn:

Br dot BP

where Br is the bot's right vector (perpendicular to look at vector) and BP is the vector from the bot to the player. Negative means turn left, positive to turn right.

Skizz

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!