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 / i dont know whats wrong with this code...

Author
Message
jasonhtml
21
Years of Service
User Offline
Joined: 20th Mar 2004
Location: OC, California, USA
Posted: 7th Jun 2005 00:23
my code is supposed to hide objects when they are far away and show them when they are close, but its not working... why?



Deathquest: 95% (MMORPG)
DD Studios Website: http://www.geocities.com/jasonhtml/
DD Studios Forum: http://s6.invisionfree.com/DD_Studios_Forum
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 7th Jun 2005 00:38 Edited at: 7th Jun 2005 00:39
This might be well off - but try absoluting your distance check, like:

dis# = abs(sqrt(((ox#-x#)^2) + ((oy#-y#)^2)))

This would set it so dis# is always positive, I think if you don't do that sometimes the distance check is negative. Worth a try at least.

One thing though - are you calling this every loop?

It strikes me that you could optimise that a little, like only checking objects that are in the screen, and only hiding/showing when absolutely necessary. For example, if you had an array that just stored the visibility state of each object, you could do something like (assuming visible(obj) is the array name):

if dis# > 1000 and object in screen(c)=1
if visible(c)=1 then hide object c : visible(c)=0
else
if visible(c)=0 then show object c : visible(c)=1
endif

Hiding and showing objects is fairly slow, so don't replicate the hiding or showing that you've already done in the previous loop. It's actually faster to check if an object is visible before hiding it than just hiding it regardless.


Van-B

jasonhtml
21
Years of Service
User Offline
Joined: 20th Mar 2004
Location: OC, California, USA
Posted: 7th Jun 2005 00:42
gah... tried using absolute value and it didn't work... btw, im already hiding objects not on the screen, but its not enough, so im doing this also...

so, anyone else know whats wrong with this?

Deathquest: 95% (MMORPG)
DD Studios Website: http://www.geocities.com/jasonhtml/
DD Studios Forum: http://s6.invisionfree.com/DD_Studios_Forum
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 7th Jun 2005 00:49
Ahhh, just spotted that your using the Y axis, I think that should be the Z...


for c = 500 to 580
if object exist(c)
ox# = Object Position x(c)
oz# = Object Position z(c)
x# = Object Position x(1)
z# = Object Position z(1)
dis# = sqrt(((ox#-x#)^2) + ((oz#-z#)^2))
if dis# > 1000
hide object c
else
show object c
endif
endif
next c


Other than that I have no clue.


Van-B

jasonhtml
21
Years of Service
User Offline
Joined: 20th Mar 2004
Location: OC, California, USA
Posted: 7th Jun 2005 23:08
thank you! i cant believe i missed that!

Deathquest: 95% (MMORPG)
DD Studios Website: http://www.geocities.com/jasonhtml/
DD Studios Forum: http://s6.invisionfree.com/DD_Studios_Forum
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 7th Jun 2005 23:10
Mathematically, a square root always returns +/-(x), but coding-wise it always produces a positive number - there's never a need to use ABS to correct it.

*** Coming soon - Network Plug-in - Check my site for info ***
For free Plug-ins and source code http://www.matrix1.demon.co.uk
Sergey K
21
Years of Service
User Offline
Joined: 4th Jan 2004
Location:
Posted: 8th Jun 2005 08:13
to get better fps on that thing, u should check if the object visible first, and then use hide/show (its a tip)

does 1 + 1 is 11?!
Pasky
19
Years of Service
User Offline
Joined: 7th Jun 2005
Location: Spain
Posted: 8th Jun 2005 18:48
Hello.
It is a game in 3D?
In 3d you must watch coordinates X, Y and Z to know the distance correct.
A vector simplifies the calculations to you.
For example:

Now I am in the office, so I cannot prove if the code that I send to you is correct.
I do not have the DBPro in the computer of the work.

If I speak rare that it is not strange to you. Not English.
I use the translator of Google.
A greeting.

Login to post a reply

Server time is: 2025-06-04 17:45:11
Your offset time is: 2025-06-04 17:45:11