Pregunta

I'am developing an isometric game, I have to calculate if an item is in the range of another, so in a normal projection a circle would be ok I mean:

 float dist = sqrt((x1-x2)^2 + (y1-y2)^2);

but as this is an isometric projection where a "x" unit is two times a "y" unity, how could I calculate the range of an item?

Any tip would be helpful

¿Fue útil?

Solución

I'm not sure whether I understand which unit is bigger than the other and in which reference system but one of the below expressions should work:

float dist = sqrt(((x1-x2)/2)^2 + (y1-y2)^2);

or

float dist = sqrt((x1-x2)^2 + ((y1-y2)/2)^2);

Otros consejos

This is the correct formula:

float dist = sqrt((x2-x1) + (2*(y2-y1))^2);

The y axis is half that of x in isometric.

Therefore the distance travelled in y is twice as much in the projection, but note this is not the same as halving the x-distance.

I hope this helps.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top