function camera_handling()
{
VECTOR tmpV2, pos_off, ang_off; //working space
vec_set(pos_off, vector(-200,0,25)); //TWEAK :: distance of camera from ball.
vec_set(ang_off, vector(0,20,0)); //TWEAK :: adjust angle of camera AFTER centered on player
var smoothness = 0.2; //TWEAK :: smaller is smoother but slower (camera lags behind a bit)
ENTITY* cam_det = ent_create(0,0,0); //used for camera-collision-detection only.
while(1)
{
if(player)
{
//position camera
vec_set(tmpV2, pos_off);
vec_rotate(tmpV2, player.pan);
vec_add(tmpV2, player.x);
vec_sub(tmpV2, camera.x);
vec_scale(tmpV2, smoothness * time_step);
c_move(cam_det, NULL, tmpV2, IGNORE_YOU|GLIDE);
vec_set(camera.x, cam_det.x);
//make sure camera has clear view of ball
if((c_trace(player.x,camera.x,NULL))&&(you!=cam_det))
{ vec_set(cam_det.x, target); vec_set(camera.x, target); }
//rotate camera toward Player
vec_set(tmpV2, player.x); vec_sub(tmpV2, camera.x);
vec_to_angle(camera.pan, tmpV2);
if(tmpV2.x<0) { camera.pan -= 180; camera.tilt = 90-(camera.tilt-90); }
vec_add(camera.pan, ang_off);
}
proc_mode = PROC_LATE;
wait(1);
}
ent_remove(cam_det);
}