I need a little help with a formula to calculate the attack range for my turn-based strat game. Since it's a hexagon grid, I'm having trouble coming up with a formula that would pick the character range variable and calculate if an enemy object is in range. I'm using Game Maker Studio 2.3. My old script used to check like this:
var unity_attack_range = attacker.RNG;
var hex_dist = 90 * unity_attack_range;
with(defender)
{
if (point_distance(defender.x, defender.y, attacker.x, attacker.y) <= hex_dist)
{
//attack code stuff
}
}
As you can see, it multiplies the attacker range variable by 90 (hexagon width/2), and then it would just point the distance between the attacker and, if inside it, then you can attack. However, I noticed it makes a circle-shaped check after the attacker with the current formula, and it will include enemies from outside the supposed range.
The hexagon shape is 180 x 120, and the distance between each hexagon center is 90 in both axis.
I don't think it will be worth entering all positions to check, since for range = 5, it would be necessary 90 positions to check manually. I need ideas on how to make it work with maths, like Civ 6 does. Any ideas? Also, thanks for the attention!