Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: Nearest object thing...  (Read 993 times)

0 Members and 1 Guest are viewing this topic.
Nearest object thing...
« on: October 15, 2007, 01:01:30 am »
  • *
  • Reputation: +1/-0
  • Offline Offline
  • Gender: Male
  • Posts: 4588
Yea, just wondering, say you had a tree and 5 apples, and you wanted to find which apple was the closest of all 5. I was thinking instance_nearest, but it returns any object.

Ideas please?
Logged
the a o d c
Re: Nearest object thing...
« Reply #1 on: October 15, 2007, 01:10:55 am »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 1141
Code: [Select]
var idd;
var sqr_distance;
var xx, yy;
idd=0;
sqr_distance=-1;//default distance
xx=x;
yy=y;
with apple
{
 if (sqr_distance==-1||sqr(xx-x)+sqr(yy-y)<sqr_distance)
 {
  sqr_distance=sqr(xx-x)+sqr(yy-y);
  idd=id;
 }
}
//idd is the id of the nearest apple. If idd=0, then there are no apple instances in the room
Logged

Goodnight

Once and future Captain
Re: Nearest object thing...
« Reply #2 on: October 15, 2007, 01:11:20 am »
  • With a Capital G
  • *
  • Reputation: +1/-0
  • Offline Offline
  • Gender: Male
  • Posts: 706
Quote from: Help file
instance_nearest(x,y,obj) Returns the id of the instance of type obj nearest to (x,y). obj can be an object or the keyword all.

Put apple for obj? Looks like it should work..
Logged
Re: Nearest object thing...
« Reply #3 on: October 15, 2007, 06:40:38 am »
  • *
  • Reputation: +1/-0
  • Offline Offline
  • Gender: Male
  • Posts: 4588
Quote from: Help file
instance_nearest(x,y,obj) Returns the id of the instance of type obj nearest to (x,y). obj can be an object or the keyword all.

Put apple for obj? Looks like it should work..
Crap *Slaps head* the word "type" threw me off. Thanks.
Logged
the a o d c
Pages: [1]   Go Up

 


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Page created in 0.233 seconds with 78 queries.