here some code to help
left and right arrow keys to turn the player up and down key to move forwards and backwards
spacebar to turn the entity towards the target
Graphics3D 800,600
SetBuffer BackBuffer()
camera=CreateCamera()
light=CreateLight()
target=CreateCone()
PositionEntity target,0,0,20
EntityColor target,30,60,200
player=CreateCube()
EntityParent camera,player
MoveEntity camera,0,2,-5
pivot=CreatePivot()
EntityParent pivot,player
MoveEntity pivot,0,0,5
rotspeed=25 ; the higher the number the slower the rotation
While Not KeyHit(1)
Cls
If KeyDown(203) Then TurnEntity player,0,1,0
If KeyDown(205) Then TurnEntity player,0,-1,0
If KeyDown(200) Then MoveEntity player,0,0,0.2
If KeyDown(208) Then MoveEntity player,0,0,-0.2
If KeyHit(57) Then
Gosub resetpivot
EntityParent pivot,0
pm=1
End If
If pm=1 Then Gosub updatepivot
UpdateWorld
RenderWorld
Flip
Wend
End
.resetpivot
RotateEntity pivot,0,EntityYaw(player),0
PositionEntity pivot,EntityX(player),EntityY(player),EntityZ(player)+5
Return
.updatepivot
PointEntity pivot,target
PointEntity player,pivot
MoveEntity pivot,0,0,EntityDistance(pivot,target)/rotspeed
If EntityDistance#(pivot,target)<0.5 Then
Gosub resetpivot
EntityParent pivot,player
pm=0
End If
Return
|