Jump to content
  • Advertisement
Sign in to follow this  
AndersEkdahl

Enemy AI, attacking on Y-axis and specific distance

This topic is 2485 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

Heya.
I have created a simple AI for one of my enemies, it will attack when i'm in a certain distance and just attack on Y-axis.
I just got the Y-axis attack to work, now i'm just trying to set a specific attack distance for it. It will come out from the wall and attack the avatar, and the attack is based on the players position.

Right at this moment the attacking is working, but it know no boundaries when to stop, this is where I need help.
How do I set that the attack distance will be like for example 100 pixels and then it can't go any further than that?

Cheers.

Share this post


Link to post
Share on other sites
Advertisement
Well, each time you want to do the attack, you can check if the distance between the enemy's position and the player's position is lower than 100 px or higher. If it is lower, commence the attack, if not, don't attack. if enemy is at (x1, y1) and player at (x2, y2) the distance would be the formula here http://easycalculati...al/distance.php.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!