How do i calculate a tower vision radius?

105 Views Asked by At

Iam making a isometric tower defense games, i was trying find some good way to make the tower enemy detection, than i find that formula:

Given tower position (Tx, Ty) and enemy position (x, y). And tower vision radius (rx and ry)

float a = (x - Tx);
a = a * a / (rx * rx)
float b = (y - Ty);
b = b * b / (ry * ry)

bool enemyInRange = a + b <= 1;

I dont know how calculate the tower vision radius since its a isometric game than rx will be depending my camera angle (x = 60º)

Another problem is that formula wont work perfectly cause some enemys have a different hitboxes size (will be a elipse too), so just enemy position wont be enough.

1

There are 1 best solutions below

7
Andrei Vukolov On

If you use orthogonal isometric projection with a view angle of 60 deg, the linear mangling coefficient is appr. 0.82 constantly. Since Z axis is mangled by a different coefficient sqrt(3)/2, just adopt your formula by multiplying the axial distances by 0.82 for X and Y, then calculate the radius and experiment with mangling on Z with multiplication by sqrt(3)/2.

If you use oblique frontal projection when the Y axis is projected on the screen plane rotated CW by 45 deg angle, the mangling coefficients are 1 for the X and Z axis, and 0.5 for the Y axis, so you should build the projected vision radius as an ellipsis by the following equation:

[pow(x, 2) / pow(R, 2)] + [pow(y, 2) / pow((R / 2), 2)] = 1