I'm trying to get my 3d object to ease to a stop and not stop suddenly when I release the key triggering it's movement. I don't have a clue how to do this. Can someone at least give me a hint?
simple motion question
Blitz3D Forums/Blitz3D Beginners Area/simple motion question Sounds like you want to be using a simple accleration/deceleration routine.
It's quite easy, set a max speed then when the acceleration key is pressed increase the speed by x increment when the key is not down reduce speed by y increment.
So accleration is:
This will allow you object ot smoothly acclerate and decelerate.
Darkheart
It's quite easy, set a max speed then when the acceleration key is pressed increase the speed by x increment when the key is not down reduce speed by y increment.
So accleration is:
speed=speed+x if speed > maxspeed then speed=maxspeed
This will allow you object ot smoothly acclerate and decelerate.
Darkheart
For a more complete example:
Graphics 640,480 SetBuffer BackBuffer() ; keyboard controls Const KUp=200 Const KDown=208 Const KLeft=203 Const KRight=205 ; position and speed xs#=0 ys#=0 x#=320 y#=240 ; acceleration and friction accel#=.2 friction#=.99 Repeat Cls ; accelerate in direction If KeyDown(kup) Then ys=ys-accel If KeyDown(kdown) Then ys=ys+accel If KeyDown(kright) Then xs=xs+accel If KeyDown(kleft) Then xs=xs-accel ; apply friction xs=xs*friction ys=ys*friction ; add resultant speed to x and y positions x=x+xs y=y+ys ; bounce off sides If x>639 Then x=639:xs=-xs If x<0 Then x=0:xs=-xs If y>479 Then y=479:ys=-ys If y<0 Then y=0:ys=-ys Oval x-6,y-6,13,13,True Flip Until KeyHit(1)
I got the first one to work but I really like the simplicity of Rob's code and it works really well on the 2d oval... but when I add the same code to my 3d object on the x and z I can't seem to get ahold of the settings. Here it is:
Graphics3D 800,600
SetBuffer BackBuffer()
camera=CreateCamera()
PositionEntity camera,0,20,20
light=CreateLight()
RotateEntity light,90,0,0
cube=CreateCube()
PositionEntity cube,0,0,7
ScaleEntity cube,.5,.5,.5
PointEntity camera,cube
; keyboard controls
Const KUp=200
Const KDown=208
Const KLeft=203
Const KRight=205
; position and speed
xs#=0
zs#=0
; acceleration and friction
accel#=.2
friction#=.99
While Not KeyHit(1)
Cls
; accelerate in direction
If KeyDown(kup) Then zs=zs-accel
If KeyDown(kdown) Then zs=zs+accel
If KeyDown(kright) Then xs=xs+accel
If KeyDown(kleft) Then xs=xs-accel
; apply friction
xs=xs*friction
zs=zs*friction
; add resultant speed to x and y positions
x=x+xs
z=z+zs
MoveEntity cube,x,0,z
UpdateWorld
RenderWorld
Text 0,20,"xs value:"+xs
Text 0,40,"accel value:"+accel
Flip
Wend
End
P.S. how do you make the sceen black with green text?
Graphics3D 800,600
SetBuffer BackBuffer()
camera=CreateCamera()
PositionEntity camera,0,20,20
light=CreateLight()
RotateEntity light,90,0,0
cube=CreateCube()
PositionEntity cube,0,0,7
ScaleEntity cube,.5,.5,.5
PointEntity camera,cube
; keyboard controls
Const KUp=200
Const KDown=208
Const KLeft=203
Const KRight=205
; position and speed
xs#=0
zs#=0
; acceleration and friction
accel#=.2
friction#=.99
While Not KeyHit(1)
Cls
; accelerate in direction
If KeyDown(kup) Then zs=zs-accel
If KeyDown(kdown) Then zs=zs+accel
If KeyDown(kright) Then xs=xs+accel
If KeyDown(kleft) Then xs=xs-accel
; apply friction
xs=xs*friction
zs=zs*friction
; add resultant speed to x and y positions
x=x+xs
z=z+zs
MoveEntity cube,x,0,z
UpdateWorld
RenderWorld
Text 0,20,"xs value:"+xs
Text 0,40,"accel value:"+accel
Flip
Wend
End
P.S. how do you make the sceen black with green text?
How about this :)
; keyboard controls Const KUp=200 Const KDown=208 Const KLeft=203 Const KRight=205 Graphics3D 800,600,16,2 Global friction#=.98 Global acc#=0.2 Global vx#,vy#,vz# CreateLight cube=CreateCube() camera=CreateCamera() PositionEntity camera,0,20,-20 PointEntity camera,cube Repeat If KeyDown(KLeft) Then TurnEntity cube,0,2,0 If KeyDown(KRight) Then TurnEntity cube,0,-2,0 If KeyDown(KUp) TFormVector 0,0,acc,cube,0 vx#=vx#+TFormedX() vy#=vy#+TFormedY() vz#=vz#+TFormedZ() EndIf vx#=vx#*friction vy#=vy#*friction vz#=vz#*friction TranslateEntity cube,vx,vy,vz RenderWorld ;green text Color 0,255,0 Text 400,10,"Green text",1 Flip Until KeyDown(1) End
.
.