How to use distance

Talk about making games.

How to use distance

Postby supaboy86 » Thu Feb 16, 2006 8:16 pm

How do you use the command "distance". Sorry about the questions i'm new at this.
supaboy86
 
Posts: 11
Joined: Fri Jan 14, 2005 2:43 am
Score: 0 Give a positive score

Postby Fuzzy » Thu Feb 16, 2006 10:19 pm

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.
Mortal Enemy of IF....THEN(and Inspector Gadget)

Still ThreeFingerPete to tekdino
User avatar
Fuzzy
 
Posts: 1068
Joined: Thu Mar 03, 2005 9:32 am
Location: Plymostic Programmer
Score: 95 Give a positive score

Postby supaboy86 » Fri Feb 17, 2006 4:38 am

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.
supaboy86
 
Posts: 11
Joined: Fri Jan 14, 2005 2:43 am
Score: 0 Give a positive score

Postby makslane » Fri Feb 17, 2006 2:14 pm

Use:

variable = distance(knight.x,knight.y,E_enemy1.x,E_enemy1.y);
Game Editor is an open source game creator software that's wants to pay it's developers to keep evolving.
If you like Game Editor, make a review!
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Postby supaboy86 » Fri Feb 17, 2006 9:11 pm

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.
supaboy86
 
Posts: 11
Joined: Fri Jan 14, 2005 2:43 am
Score: 0 Give a positive score


Return to Game Development

Who is online

Users browsing this forum: No registered users and 1 guest