문제

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

도움이 되었습니까?

해결책

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);

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top