Page 1 of 1

How to use distance

PostPosted: Thu Feb 16, 2006 8:16 pm
by supaboy86
How do you use the command "distance". Sorry about the questions i'm new at this.

PostPosted: Thu Feb 16, 2006 10:19 pm
by Fuzzy
Distance takes four arguements. It takes two sets of X and Y coordinates, and returns a distance. You use it to set a variable. Here is how you would use it.

HowFar = Distance(supaboy.x,supaboy.y,moon.x,moon.y);

Just for kicks and giggles, here is how to calculate it by hand, so you can use it in real life.

D^2=abs(x1^2-x2^2)+(y1^2-y2^2), see why we let Makslane and GE figure it out for us?

Seriously, if i was standing at x=3 and y=4, and you are at x=0 and y=0, the distance I would be from you is five units away.

D^2=(3^2-0^2)+(4^2-0^2) or
D^2=(9-0)+(16-0) which is equal to
D^2=25.

So now all we have to do is eliminate the ^2. to do that, find the square root of 25, which is 5. D=5! abs means absolute, and it eliminates a negative sign.

PostPosted: Fri Feb 17, 2006 4:38 am
by supaboy86
I am still not sure how to use the code, i tried stuff like this:
Code: Select all
50=Distance(knight.x,knight.y,E_enemy1.x,E_enemy1.y);

and all this error stuff came up. Precisly, I want to figure out a code like: if distance between enemy1 and landmine == 1 then destroy landmine.

PostPosted: Fri Feb 17, 2006 2:14 pm
by makslane
Use:

variable = distance(knight.x,knight.y,E_enemy1.x,E_enemy1.y);

PostPosted: Fri Feb 17, 2006 9:11 pm
by supaboy86
Thanks alot for that huge tip it really worked!! But I have another problem with my army, I do not want the men to walk to close to each other, so I tried making them stop for 1/5 of a second, that didn't turn out too well. Do you know how to keep them from getting to close to each other while still moving like in War Craft 3? Sorry for all the questions, i'm hopig that this will be my last one for a long time.