code for back and forth motion?

Blitz3D Forums/Blitz3D Beginners Area/code for back and forth motion?

timmport(Posted 2006) [#1]
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



Stevie G(Posted 2006) [#2]
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



timmport(Posted 2006) [#3]
Thanks so much. This is exactly what I needed and also helps me to understand basic a bit more.


GfK(Posted 2006) [#4]
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



Ross C(Posted 2006) [#5]
Smooooth