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.

DarkBASIC Professional Discussion / Calculating Distance and Returning a Variable Depending on the Closest Object

Author
Message
Preston C
23
Years of Service
User Offline
Joined: 16th May 2003
Location: Penn State University Park
Posted: 11th Oct 2003 18:38 Edited at: 11th Oct 2003 18:43
I'm having problems with it. Always returns that object number illegal at line 120 when I try to lockon to the closest enemy sphere. Could someone please help? Thanks. Code is in the code box.

PS: You Can use any old 128x128 image for lockon.bmp

Edit: Rich, please, please put source code editing in your posts in the future.




zircher
23
Years of Service
User Offline
Joined: 27th Dec 2002
Location: Oklahoma
Posted: 11th Oct 2003 20:25
As I expected, objectlock = 0 is what causes the error. The flaw in your logic is that you never initialize objectdistance or objectlock. Since objectdistance defaults to zero, nothing EVER can be closer, so objectlock is never set to a valid object.

Updated code follows.
--
TAZ

IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 11th Oct 2003 20:29
Try substituting this code in the appropriate place ...



It doesn't crash, but only you can tell me if it's the effect you are after
Preston C
23
Years of Service
User Offline
Joined: 16th May 2003
Location: Penn State University Park
Posted: 11th Oct 2003 23:47 Edited at: 11th Oct 2003 23:53
Neither Work, they only lock on to object 2, not object 3 It needs to lock on to the closest one. Oh well, back to coding.


zircher
23
Years of Service
User Offline
Joined: 27th Dec 2002
Location: Oklahoma
Posted: 12th Oct 2003 07:25
You wrote the code. I just pointed out what was causing the fatal error.
--
TAZ
Preston C
23
Years of Service
User Offline
Joined: 16th May 2003
Location: Penn State University Park
Posted: 12th Oct 2003 18:01
Yeah, that did help, thanks. Well, I still cant get it right, but I gotta finish this engine, its one of 4 I need for...it


Philip
23
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 13th Oct 2003 09:09
Er... this may be a REALLY silly question (in which case I humbly withdraw it) but why have you created a bespoke distance function based on pythagorous' masterstroke?

Why not just create a Vector3 between the coordinates of two objects and then return the vector's length using the built in DBP commands that do both? The Vector3's length is the distance and its a lot easier than writing bespoke functions.

Possibly its slower. Possibly I'm mad. Possibly 1/10 really is 0.000000149. Who knows?

The only real question here is: is Doctor Who really going to be re-made by BBC Wales? And when do I get to watch it?

And who am I? And who are you? And is this my tenth beer already?

Randomly yours

Philip

What do you mean, bears aren't supposed to wear hats and a tie?
zircher
23
Years of Service
User Offline
Joined: 27th Dec 2002
Location: Oklahoma
Posted: 13th Oct 2003 16:12
NWC Omega, let me know if you're still stuck and I'll revist the code. BTW, Philip does have a vaild point. DBP does have some built in functions that might help. Or at the very least, it could be interesting to run both examples and see which is faster.
--
TAZ
Preston C
23
Years of Service
User Offline
Joined: 16th May 2003
Location: Penn State University Park
Posted: 13th Oct 2003 16:30
1: I dont use vectors or any of the other functions that would make it easier because I dont know how.
2: I asked how to use vectors before and you all said they were silly and didnt have any use.

Either way, I found the problem, and everythings fine now. Thanks for the help all.


Philip
23
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 14th Oct 2003 08:26
Whoever said Vectors are silly and have no use should be shot.

Vectors (and matrix math) is the very basis of all 3d graphics.

Philip

What do you mean, bears aren't supposed to wear hats and a tie?

Login to post a reply

Server time is: 2026-07-26 04:27:11
Your offset time is: 2026-07-26 04:27:11