🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Enemy AI, attacking on Y-axis and specific distance

Started by
1 comment, last by mltomg 4 years, 5 months ago
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.
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.

Use our free on line mg to mL converter to transform your values from milligram to milliliters. Milligram (mg) is a small unit of mass in metric system, which is 1/one thousand of a gram (zero.001 Milliliter). 1 Milliliter is equal to a thousandth of a liter. It is also identical to 1 cubic centimeter, or about 15 minims. https://www.mathauditor.com/ml-to-mg.html Milligrams and Milliliters are typically used measurement devices used round the sector. Any unit of dimension inclusive of Milligrams, liters, kiloliters, and so forth. Can be transformed to the other devices of drinks. The conversion of milligrams to milliliters is useful in fluid mechanics and chemical compositions. Make use of this Milligram to Millilitre calculator and simplicity your calculations.

This topic is closed to new replies.

Advertisement