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 / Distance function wont work.

Author
Message
Mugen Wizardry
User Banned
Posted: 30th Jul 2010 17:41
What is wrong with my distance function?
i need GetDist() to return the distance between either the camera and the object or the object and the object depending on if camon=1..



CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD! http://www.imageposeidon.com/
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 30th Jul 2010 18:20
I think maybe that dist function needs to be...

Function Dist#(x1#,x2#,y1#,y2#,z1#,z2#)
Set Vector3 1,x1#-x2#,y1#-y2#,z1#-z2#
rdist#=Length Vector3(1)
EndFunction rdist#

Because a function has to be set to the same variable type as it returns.

Health, Ammo, and bacon and eggs!
Mugen Wizardry
User Banned
Posted: 30th Jul 2010 18:21
didnt work

CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD! http://www.imageposeidon.com/
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 30th Jul 2010 18:28
Quote: "What is wrong with my distance function?"


I'd guess that your "if/else" conditions inside the case statements are your problem, but since you give no information about the values you are using and the values you get for your function it's hard to be more precise.

One thing is certain though, if camon is 0 and obj2 is also zero then your x, y and z values will all be undefined (they'll be zero if an old bug has been fixed) and your program will either fail completely or you'll get a distance of zero returned by your functions.

I suspect you've got a bit muddled in your use of case and if statements.
Mugen Wizardry
User Banned
Posted: 30th Jul 2010 18:35
camon tells it if the player is a camera

cam is the id of the camera if camon=1

obj1 is the 1st object (the player)

obj2 is the target object

CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD! http://www.imageposeidon.com/
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 30th Jul 2010 18:45
Actually your code works if you use it correctly. What values are you using for camon, etc?

Here's what I used to test your code (I used the default camera 0 - but you should be able to use any camera with your code):

Mugen Wizardry
User Banned
Posted: 30th Jul 2010 18:55
its returning incorrect number.

the values i use are the 1s in the parameters of the function call



thanks!

CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD! http://www.imageposeidon.com/
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 30th Jul 2010 20:26
Quote: "the values i use are the 1s in the parameters of the function call "


I know that silly. What are the values of those variables?

Is cam = 0 or 1?

Is obj1 = 0, 1, 2 or something else?

Etc, etc.

Did you try the code snippet I gave you? It returns the correct values in each case, i.e. with "c" pressed or not pressed. What values do you get?

[There is a silly typo in my text statement which may have misled you - the value printed is correct but the caption isn't. The corrected part should be:



With cam = 0 I get 141 which is correct, i.e. the distance between the camera and object 1.
With cam = 1 I get 200 which is also correct, i.e. the distance between objects 1 and 2.

What values do you expect from your code? Have you got cases 0 and 1 the right way round?
Mugen Wizardry
User Banned
Posted: 30th Jul 2010 20:36
i fixed it.

however im having another problem with my text code, and could really use some help on it.

See my other thread

Thanks,Gandalf!

CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD! http://www.imageposeidon.com/

Login to post a reply

Server time is: 2026-07-25 08:29:47
Your offset time is: 2026-07-25 08:29:47