Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Finding the smallest value

Author
Message
Nameless
20
Years of Service
User Offline
Joined: 11th Apr 2004
Location: U.S.A.
Posted: 10th Aug 2006 20:55
So I want to have missles that guide themselves into the nearest enemy. I know you have to find the distance between the missle and your enemies and I know how to do that I'm just not sure how you would compare the different distance values to find the smallest. If any one could explain this for me I would be very grateful.
Scraggle
Moderator
21
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 10th Aug 2006 21:01 Edited at: 10th Aug 2006 21:04
Assign the distances to an array then cycle through the array to find the smallest value with this:



Nameless
20
Years of Service
User Offline
Joined: 11th Apr 2004
Location: U.S.A.
Posted: 10th Aug 2006 21:04
I have them assigned to an array I just don't know how to cycle through them for the smallest value. Thanks for the quick reply.
Scraggle
Moderator
21
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 10th Aug 2006 21:05 Edited at: 10th Aug 2006 21:05
Check my edit above^

The array named Distance would need to be renamed to whatever you have called it.


Nameless
20
Years of Service
User Offline
Joined: 11th Apr 2004
Location: U.S.A.
Posted: 10th Aug 2006 21:26
Would that really compare it to all of the other distances or just the enemy that is one object number below it?
Scraggle
Moderator
21
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 10th Aug 2006 21:37
Try it


lower logic
18
Years of Service
User Offline
Joined: 15th Jun 2006
Location:
Posted: 10th Aug 2006 22:36 Edited at: 10th Aug 2006 22:37

I could be wrong, but this code snippet looks like it would set Closest to k whenever an element in the array is less than the one before it. If that's true, then it wouldn't return the closest in an array like [6 3 9 8]. It would see 3<6 so Closest would be 3, but then it would see 8<9, so it would set Closest to 8, forgetting about 3.

Here's what I'd do to find the closest:

If this piece of code went through the example array [6 3 9 8], it would first set closest to 1 and closestdist to 6 (before the loop). Then it would see 3<6, so it would set closest to 2 and closestdist to 3. The last two checks would be 9<3 and 8<3, both of which are false, leaving closest at 2.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 11th Aug 2006 02:37 Edited at: 11th Aug 2006 02:38
I believe you're right logic.

Here's a method using a sort of bitwise IF statement. It acts like that alternate C++ IF method: k = (x<y)?x:y;



"Using Unix is the computing equivalent of listening only to music by David Cassidy" - Rob Pike
Nameless
20
Years of Service
User Offline
Joined: 11th Apr 2004
Location: U.S.A.
Posted: 11th Aug 2006 15:26
Thanks for the replies guys that really helped me.
jokeguy 1441
18
Years of Service
User Offline
Joined: 24th Jun 2006
Location:
Posted: 11th Aug 2006 22:01
btw... i dont bother myself with those distance number thingys ... i just make a sphere, and posiiton it at the object that i want to make distance with... and if some object collisises that sphere than ........blablabal... blow up the boulding-...... or something like that

Your signature has been erased by a mod

Login to post a reply

Server time is: 2024-09-25 05:32:54
Your offset time is: 2024-09-25 05:32:54