Ok man. I've fixed your problems and added a few more things in. Added in hovering above the track and some better acceleration for the ship. Added in comments too, to explain what i've done. Any questions, just post em back in here :o)
Graphics3D 800,600,16,2
Text 320,200,"Please Wait, Loading Data...."
SetBuffer BackBuffer()
; Setup contants and varibles as used in the driver example and modified for what I think I need.
Const GRAVITY#=-5
Const BODY=1,WALL=2,RACETRACK=3,SHIPPIVOT=4
Global dist_above_track# = 50 ; Distance Above Track That Ship Hovers.
Global hover = 0 ; hover variable to control the hovering above the track
Global hover_speed = 1 ; speed the craft will hover
Global hover_range = 10 ; hover range of distance
Global dist_away_from_wall# = 50
Global bank_angle# = 0
Global max_speed# = 80 ; Maximum Speed The Ship Can Go.
Global speed# = 0 ; Set Speed To 0 At Start.
Global displayspeed# = 0
; Load required Track & Walls and set them up as needed. This includes linking to any variables.
Global track=LoadMesh ("Media/TestTrack3a.3ds")
Global walls=LoadMesh ("Media/TestTrack3b.3ds")
Global scenery=LoadMesh ("Media/TestTrack3c.3ds")
PositionEntity track,0,0,0
PositionEntity walls,0,0,0
PositionEntity scenery,0,0,0
RotateEntity track,0,0,-90
RotateEntity walls,0,0,-90
EntityType track,RACETRACK
EntityType walls,WALL
EntityPickMode track,2
EntityPickMode walls,2
tex=LoadTexture( "Media/tiles.jpg" )
ScaleTexture tex,50,50
EntityTexture track,tex
; Now do the same for the ship (this replaces the car in the driver example).
Global ship=LoadMesh ("Media/fighter.3ds")
RotateMesh ship,0,180,0 ; ADDED <<<< Rotate the mesh so it's facing the +Z. Makes moving it more
; straightforward. Rotatemesh is perminate, and doesn't reset like rotateentity.
PositionEntity ship,0,20,0
EntityShininess ship,1
EntityType ship,BODY
ScaleEntity track,.05,.05,.05
ScaleEntity walls,.05,.05,.05
ScaleEntity scenery,.05,.05,.05
ScaleEntity ship,.05,.05,.05
; Set up the main light for the scene.
light=CreateLight()
PositionEntity (light,0,10,-10)
; Now get the camera up and running...
Global camera = CreateCamera()
CameraRange camera,1,10000
CameraFogMode camera,1
CameraFogRange camera,100,9000
PositionEntity camera,0,25,70
PointEntity camera,ship
Global cam_piv = CreatePivot() ; create camera pivot
; this camera pivot is where the camera will come to rest when motionless
EntityParent cam_piv, ship ; parent the pivot to the ship
PositionEntity cam_piv,0,325,-470 ; location of the pivot in relation to the ship
Global cam_look_piv = CreatePivot() ;the point the camera will point to.
EntityParent cam_look_piv, ship
PositionEntity cam_look_piv,0,150,200
Global cam_speed = 10 ;the speed the camera will align to the ship at. Lower values = faster alignment
; Setup collisions
Collisions BODY,RACETRACK,2,2
Collisions BODY,WALL,2,1
; Setup other variables
camx#=0 ; Camera X Angle.
camy#=0 ; Camera Y Angle.
camz#=0 ; Camera Z Angle.
pitch#=0 ; Camera & Ship Rotation Angle.
; Okay that should be everything up and running. Now it is time to do the main program loop.
While Not KeyHit(1)
;move ship
If KeyDown(203)
camy=camy+1
TurnEntity ship,0,1,0
ElseIf KeyDown(205)
camy=camy-1
TurnEntity ship,0,-1,0
EndIf
; These lines i put in below replace the old ones you had. This makes the speeding up and slowing down
; more "real" looking. It does this by using the SIN wave. /-\_/ The closer the speed variable
; gets to 90, the exponetially faster the speed gets. It simulates acceleration quite well.
If KeyDown(200)
speed = speed + 0.4
If speed > max_speed Then
speed = max_speed
End If
ElseIf KeyDown(208) Then
speed = speed - 0.4
If speed < 0 Then
speed = 0
End If
Else
speed = speed - 0.2
If speed < 0 Then
speed = 0
End If
End If
sx#=EntityX(ship,True)
sy#=EntityY(ship,True)
sz#=EntityZ(Ship,True)
LinePick sx,sy,sz,0,-100,0
hover = hover + hover_speed
If PickedEntity()<>0
AlignToVector ship,PickedNX(),PickedNY(),PickedNZ(),2,0.2
; the same idea as the speed, using the sin wave to hover the ship. Perfect for this type
; of thing, as all you do is increase the hover variable by a constant number (hover_range)
; to get the ship to simulate a hovering motion. No need to reset the variable, as this is
; not needed.
PositionEntity ship, sx, PickedY() + dist_above_track + (Sin(hover)*hover_range), sz,True
EndIf
; As explained above, the movement uses the SIN wave. You basically move the ship using the
; SIN of the speed variable. Because sin values only range from -1 to 1, you need to multiply
; the result by a number to obtain faster speeds
MoveEntity ship,0,0,Sin(speed)*20
displayspeed = speed
; perform smooth camera operations
; these code lines point the camera at the cam_pivot, then moves the camera towards that point,
; based on the distance remaining between them. It gives a smooth movement because the distance
; is decreasing as the camera moves, and thus, the speed it moves at decreases the closer it gets
; to the point. The cam_look_piv, is basically just a pivot the camera points to, instead of pointing
; at the ship. Gives a beter view of the track. Both pivots are parented to the ship, so they move
; along with it
PointEntity camera, cam_piv
MoveEntity camera,0,0,EntityDistance(cam_piv,camera)/ cam_speed
PointEntity camera, cam_look_piv
UpdateWorld
RenderWorld
Text 320,500,"Racer V0.01"
Text 320,520,"Speed:"
Text 380,520,displayspeed
Flip
Wend
End
|