modifying movement speed
Blitz3D Forums/Blitz3D Beginners Area/modifying movement speed
| ||
I have created 3 cubes that bounce up and down using an if statement that reverses the direction of the cube once it has moved a number of units. I am attempting to speedup or slowdown the speed the cubes bounce by pressing one of 3 keys. When I press one of the keys the speed of the cube changes but does not reverse direction essentially the cube "runs away". Can someone point out what I am doing wrong?Graphics3D 640, 480, 0, 2 cam = CreateCamera () TurnEntity cam,15,0,0 PositionEntity cam,0,25,-20 lite = CreateLight() cube1=CreateCube() PositionEntity cube1,-10,0,20 cube2=CreateCube() PositionEntity cube2,0,0,20 cube3=CreateCube() PositionEntity cube3,10,0,20 Global zz = .51 Global xx = .51 Repeat bounce = bounce + zz If Abs(bounce) => 5 zz = -zz MoveEntity cube1,0,bounce,0 MoveEntity cube2,0,bounce,0 MoveEntity cube3,0,bounce,0 ;---these keys are meant to speed up the bouncing motion-------- ; the "q" key If KeyDown( 16 )=True Then zz = .55 ; the "w" key If KeyDown( 17 )=True Then zz = .60 ; the "e" key If KeyDown( 18 )=True Then zz = .65 UpdateWorld RenderWorld Text 20, 20, bounce Flip Until KeyHit (1) End |
| ||
First of all use floats to initialise zz , bounce etc... Blitz is rounding zz up to 1 in all cases which is why the speed doesn't change. Also, when you press the key you need to take into consideration the direction the cube is moving, otherwise it will always move upwards. if keydown(16) zz= sgn( zz ) * .55 Not sure what you're trying to do but I'd imagine that you would want to limit the y axis movement to +-5. Instead of moveentity you may be better using PositionEntity cube1,-10,bounce,20 PositionEntity cube2,0,bounce,20 PositionEntity cube3,10,bounce,20 Hope this helps. Stevie |