Hello,
I'm making a simple tank game using the Aum 12 template and having difficulty with the camera collision.
While there are many scripts out there that deal with this I cannot seem to extract the code and
add to my project. I've tried KOH and others.
I would like a simple camera that stays behind the player and zooms in if the view is obscured by a
block or model eg building. That's it really.
Just wondered if someone had a simple collision code for cameras that will zoom towards the player
if this happens.
My code is below but shakes and does not zoom in when the camera is blocked by models.
FUNCTION handle_3rd_camera() {
camera_tilt = clamp(camera_tilt,-30,10);
camera.z=my.z+180;
temp = fcos(camera_tilt,-camera_distance);
vec_set(camera_move_to.x,vector(my.x + fcos(camera.pan,temp),my.y + fsin(camera.pan,temp),my.z + 20 + fsin(camera_tilt,-camera_distance)));
temp = min(1,0.5 * time); //changing 0.5 will change how fast the camera moves, at 1 places us at target, this value is what allows the smooth movement
camera.x += temp*(camera_move_to.x - camera.x);
camera.y += temp*(camera_move_to.y - camera.y);
camera.z += temp*(camera_move_to.z - camera.z);
vec_diff(temp.x,camera.x,my.x);
vec_normalize(temp.x,16);
vec_add(temp.x,camera.x);
c_trace(my.x,temp.x,ignore_me|ignore_passable);
IF (result > 0) {
vec_diff(temp.x,my.x,target.x);
vec_normalize(temp.x,16);
vec_set(camera.x,target.x);
vec_add(camera.x,temp.x);
}
}
action player_tank
{
my.scale_x=0.75;
my.scale_y=0.75;
my.scale_z=0.75;
player = me;
my.enable_impact = on;
my.enable_entity = on;
my.event = tank_damaged;
my.passable=off;
my.polygon=on;
ent_create(challenger_turret, nullvector, attach_player_turret);
ent_create(challenger_barrel, nullvector, attach_player_barrel);
my.shield = 250; // 250 shield points for player's tank
while (my.shield > 0) // the 10th hit will destroy player's tank
{
handle_camera();
//movement code here
}
thanks,
Rob