Public Group

# 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.

## 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 on other sites
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 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 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 on other sites
thanks! I'll try that.

##### 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 on other sites
I'll give that a try. I couldn't seem to get my head around the first suggestion but I understand this one.

##### Share on other sites
It works! You da man! Thank you so much! :)

##### 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 on other sites

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

1. 1
Rutin
24
2. 2
3. 3
4. 4
JoeJ
18
5. 5

• 14
• 19
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631760
• Total Posts
3002176
×