Jump to content
  • Advertisement
Sign in to follow this  
MrChrisnis

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.

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

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 this post


Link to post
Share on other sites
Advertisement

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 this post


Link to post
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 this post


Link to post
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 :-)

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!