My IF won't work

Blitz3D Forums/Blitz3D Beginners Area/My IF won't work

SkyCube(Posted 2005) [#1]
HEEELP! My IF won't work!

I am trying to make a simple "camera floating" effect. When the camera's height reaches a certain level, it's supposed to come back down, but nothing's happenning. Here's my code

Graphics3D 800,600

SetBuffer BackBuffer()

cam = CreateCamera()
PositionEntity cam,0,0.6,0

plane = CreatePlane()
ptex = LoadTexture("bluesky2.bmp")
ScaleTexture ptex,1200,1200
EntityTexture plane,ptex
FreeTexture ptex

gravity#=0.5
cam_grav#=-0.5
While Not KeyDown(1)


MoveEntity cam,0,gravity#,0

If EntityY(cam,1)=100 Then gravity#=-0.5
  


UpdateWorld
RenderWorld
Text 0,0, Str(EntityY(cam))
Text 0,40,Str(gravity#)
Flip


Wend
End



Stevie G(Posted 2005) [#2]
Use Entityy( cam,1) >=100 then gravity# = -.5

Either that or start the camera at 0,.5,0 ... .6 is not a multiply of .5 so the ypos will never equal 100

Stevie


LKFX(Posted 2005) [#3]
what about,

gravityamount#=.5

while not keydown(1)

;update gravity
gravity#=gravity#=+gravityamount#
If EntityY(cam,1)>100 or EntityY(cam,1)<0
gravityamount#=-gravityamount#
endif

wend
if i`ve typed it right your camera should float up until 100 then come back down till 0 then go up and so forth!
plus u can alter the amount of gravity by using gravityamount varible.


LKFX


Sledge(Posted 2005) [#4]

6 is not a multiply of .5 so the ypos will never equal 100



Even if he uses multiples, rounding errors may make the comparison fail when it is expected to succeed. I would only dare compare integers like that, using a range for floating point values instead (as with LKFX's code).

EDIT: Eg http://www.blitzbasic.com/Community/posts.php?topic=25990&hl=floating%20point%20error