///////////////////////////////////////////////////////
// INCLUDES
///////////////////////////////////////////////////////
#include <acknex.h>
#include <default.c>
///////////////////////////////////////////////////////
// VARIABLES
///////////////////////////////////////////////////////
VECTOR offset;
ENTITY* cam;
ENTITY* actor;
ENTITY* tcam;
var attach;
//////////////////////////////////////////////////////
// ACTIONS
//////////////////////////////////////////////////////
action camera_action(){
cam = me;
while (me!=NULL){
wait(5);
camera.x = cam.x;
camera.y = cam.y;
camera.z = cam.z;
camera.pan = cam.pan;
wait(5);
}
}
action actor_action(){
actor = me;
}
action tcam_action(){
tcam = me;
while (me!=NULL)
{
if (actor!=NULL)
{
my.x = actor.x;
my.y = actor.y;
my.z = actor.z;
my.pan = actor.pan;
}
wait(5);
}
}
/////////////////////////////////////////////////////
// FUNCTIONS
/////////////////////////////////////////////////////
function initCamOffset(ox,oy,oz){
offset.x = ox;
offset.y = oy;
offset.z = oz;
cam.x += offset.x;
cam.y += offset.y;
cam.z += offset.z;
return vector(cam.x,cam.y,cam.z);
wait(5);
}
function attachCam(){
attach = true;
wait(5);
}
function removeCam(){
attach = false;
wait(5);
}
function actorForward(){
c_move(actor,vector(4 * time_step,0,0),nullvector,GLIDE);
c_move(cam,vector(4 * time_step,0,0),nullvector,GLIDE);
wait(5);
}
function actorBackwards(){
c_move(actor,vector(-4 * time_step,0,0),nullvector,GLIDE);
c_move(cam,vector(-4 * time_step,0,0),nullvector,GLIDE);
wait(5);
}
////////////////////////////////////////////////////
// MAIN
////////////////////////////////////////////////////
function main(){
// load level
level_load("game.wmb");
wait(5);
// initialise the offset
initCamOffset(30,0,15);
// tcam set up
attachCam();
ent_create(NULL,nullvector,tcam_action);
while (1){
while (key_cuu){
actorForward();
wait(1);
}
while (key_cud){
actorBackwards();
wait(1);
}
if (key_cur){
attachCam();
while (key_cur){
actor.pan -= 8 * time_step;
// trouble-maker line - the cause of the crash
if (tcam!=NULL)
c_move(tcam,vector(offset.x,0,0),nullvector,IGNORE_MODELS);
cam.x = tcam.x;
cam.y = tcam.y;
cam.z = tcam.z;
cam.pan = tcam.pan;
wait(5);
}
removeCam();
}
wait(1);
}
}