The way I implement a chase cam (I got this from Rob Farley), is to create a pivot.
Now, the pivot is called "Cam_Final", is the place where the camera will stop chasing, should the mesh/entity be stopped. This is where the camera will rest. It is parented to the mesh/entity you want to follow.
The camera will, every loop, move towards this pivot, whilst looking at the mesh/entity your following. Remember the camera isn't following the entity, rather the pivot attached to it.
Now, to achieve this, you only need 3 simple lines of code, within a function:
; entity refers to the entity to be followed
; camera refers to the camera you wish do to the following
; Cam_Final is the pivot that will hold the location for the camera to chase
; speed is how quickly the camera will move towards the resting point. The larger the number, the slower the movement. You do not need to pass this value to the function. It will default to 30.
Function update_chase_cam(camera,entity,speed#=30)
PointEntity camera,Cam_Final
MoveEntity camera,0,0,EntityDistance#(entity,chase_cam)/speed
PointEntity camera,entity
End Function
Now to use that function, you simply create your camera, entity and your pivot. Something like:
[code]
Graphics3d 800,600
SetBuffer BackBuffer()
Global camera = CreateCamera()
Global Cam_Final = CreatePivot()
Global entity = CreateSphere()
EntityParent Cam_Final, camera
PositionEntity Cam_Final,0,2,-20 ; the position you want the camera to be, behind the entity.
While Not KeyHit(1)
If KeyDown(200) then MoveEntity entity,0,0,1
If Keydown(208) then MoveEntity entity,0,0,-1
If KeyDown(203) then TurnEntity entity,0,-1,0
If KeyDown(205) then TurnEntity entity,0,1,0
Update_Chase_Cam(camera,entity,30)
UpdateWorld
RenderWorld
Flip
Wend
; entity refers to the entity to be followed
; camera refers to the camera you wish do to the following
; Cam_Final is the pivot that will hold the location for the camera to chase
; speed is how quickly the camera will move towards the resting point. The larger the number, the slower the movement. You do not need to pass this value to the function. It will default to 30.
Function update_chase_cam(camera,entity,speed#=30)
PointEntity camera,Cam_Final
MoveEntity camera,0,0,EntityDistance#(entity,chase_cam)/speed
PointEntity camera,entity
End Function
/[code]
Unfortunately I'm at work, and I can't test any of that. But that is the basic way i would do it.