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 / Strange behavior in my loop

Author
Message
Heiner Hink
20
Years of Service
User Offline
Joined: 17th May 2004
Location:
Posted: 1st Jun 2004 20:03
Hi there,

i made a small loop, which does a back and forth movement for my camera. The code looks like this:

do
position camera 1, 0, 30, Ort#
if Ort# < 100 and done = 0
Ort# = Ort# + 0.5
if Ort# = 100 then done = 1
endif

if Ort# > -60 and done = 1
Ort# = Ort# - 0.5
if Ort# = -60 then done = 0
endif
loop

The strange thing what happens is, that as long as I increment and decrement my variable Ort by 1 or by 0,5 it works well. But if i increment, decrement only a value of 0,2 or 0,1, the camera just moves forward, but not backward anymore, which it does, when i use 1 or 0.5.
Any ideas why this is?
Thanks!
Heiner

Beeing creative is a profession, not a task
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 1st Jun 2004 20:35
floats may never end up exactly on the value you expect, like 0 or 100. Print the values during the loop and see


* DBP_NETLIB_v1.2 - NOW WITH VARIABLE WATCHER! * Click Logo
Lampton Worm
22
Years of Service
User Offline
Joined: 4th Sep 2002
Location: United Kingdom
Posted: 3rd Jun 2004 14:16
Yup... also a quick fix is to change...

if Ort# = 100 then done = 1

to...

if Ort# >= 100 then done = 1

...and the same for your other condition, so when Ort# reaches 100.000327623 or whatever, done will be set to 1.

Cheers.
Lampton Worm
22
Years of Service
User Offline
Joined: 4th Sep 2002
Location: United Kingdom
Posted: 3rd Jun 2004 14:18
...actually, if you want a smoother effect, use sin/cos, can't recall exactly, but it's something like...

make object cube 1,5
position camera 0,0,-50
do
inc blah,1
x#=sin(blah)*25
position camera x#,0,0
done

Untested

Cheers.

Login to post a reply

Server time is: 2024-09-22 11:19:39
Your offset time is: 2024-09-22 11:19:39