# C++ AI Coordinate movement

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

## Recommended Posts

I am currently working on programming a basic text based wizard game. I have my movements working for coordinates (north = x+1, east = y+1 etc.) and I am just wondering how you could code it so that the AI moves randomly on coordinates in close proximity to you. The idea is that after moving around for a bit you will land on the same coordinates as your opponent and enter a battle.

Thanks
Chris

##### Share on other sites

I am currently working on programming a basic text based wizard game. I have my movements working for coordinates (north = x+1, east = y+1 etc.) and I am just wondering how you could code it so that the AI moves randomly on coordinates in close proximity to you. The idea is that after moving around for a bit you will land on the same coordinates as your opponent and enter a battle.

Thanks
Chris

Do you mean the enemy should be aware of the player's position when its moving so that it keeps being inside a specific proximity of the player?

##### Share on other sites
Yeah, that would be quite helpful. I want it so that it doesn't take ages to find the enemy, but it isn't just first move = fight.

Thanks
Chris

##### Share on other sites
here is some pseudo code that came to my mind right now:

 vec2d dist = distVec(player, enemy) if (dist.x > MAX_DIST) enemy.x-- // depending on what u want else if (dist.x < -MAX>DIST) enem.x++ if (dist.y > MAX_DIST) enemy.y-- else if (dist.y < - MAX_DIST) enemy.y++ 

that should keep the enemy within a certain range to the player.. if u want the enemy to chase u, u can do the following pseudocode:

 if (enemy.x < player.x) enemy.x++ etc.. 

than the enemy goes terminator style after u..

hope to have helped u, it took a while to get your problem ^^ (and i am still not sure if that was what u wanted to know :-)

1. 1
2. 2
Rutin
21
3. 3
4. 4
frob
17
5. 5

• 9
• 33
• 13
• 13
• 10
• ### Forum Statistics

• Total Topics
632582
• Total Posts
3007207

×

## Important Information

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!