code for back and forth motion?
Blitz3D Forums/Blitz3D Beginners Area/code for back and forth motion?
| ||
I am new to blitz basic script and have been trying to figure this very simple thing out. How do I scipt a cube so that it rotates back ank and forth like a pendulum. i.e. in a constant clockwise then counter-clockwise motion? So far I have not even been succesful in getting my cube to rotate in on direcetion then stoping. Here is my code so far. Any help would be very much appreciated:Graphics3D 320,240,0,2 SetBuffer BackBuffer() camera=CreateCamera() CameraClsColor camera,0,0,127 PositionEntity camera,0,0,-5 light=CreateLight() cube = CreateCube() While Not KeyDown(1) While z#<20 z# = z# +1 Wend TurnEntity cube,0,0,z# RenderWorld Flip Wend End |
| ||
Like this?Graphics3D 320,240,0,2 SetBuffer BackBuffer() camera=CreateCamera() CameraClsColor camera,0,0,127 PositionEntity camera,0,0,-5 light=CreateLight() cube = CreateCube() Dir = 1 While Not KeyDown(1) z = z + Dir if abs( z ) = 20 Dir = - Dir rotateEntity cube,0,0,z RenderWorld Flip Wend End |
| ||
Thanks so much. This is exactly what I needed and also helps me to understand basic a bit more. |
| ||
Alternatively, if you require smoother movement:Graphics3D 320,240,0,2 SetBuffer BackBuffer() camera=CreateCamera() CameraClsColor camera,0,0,127 PositionEntity camera,0,0,-5 light=CreateLight() cube = CreateCube() Angle = 1 While Not KeyDown(1) Angle = Angle + 1 If Angle > 359 Then Angle = 0 RotateEntity cube,0,0,Sin(angle) * 20 RenderWorld Flip Wend End |
| ||
Smooooth |