action playercam()
{
my.albedo=0;
VECTOR temp[3];VECTOR temp2[3];VECTOR temp_target[3];VECTOR pos1[3];VECTOR pos2[3];
var anim_percentage;
var rot_speed = 6; /////new var
var new_angle;///////new var
vec_set(temp_target,my.x);
on_i = toggle_inventory;
player = my; // I'm the player
while(1)
{
if(mouse_left)
{
pos1.x = mouse_pos.x;pos1.y = mouse_pos.y;pos1.z = 0;
vec_for_screen (pos1, camera);
pos2.x = mouse_pos.x;pos2.y = mouse_pos.y;pos2.z = 20000;
vec_for_screen (pos2, camera);
c_trace (pos1,pos2,IGNORE_ME|IGNORE_PASSABLE|IGNORE_MODELS);
vec_set(temp_target,target);
}
if(vec_dist(my.x,temp_target.x)>20)
{
//vec_set(temp.x,temp_target.x);
//vec_sub(temp.x,my.x) ;
//vec_to_angle(my.pan,temp);
//my.pan = smooth(my.pan, 0.95);
////////////////////////////////////////////////new code//////////////////////////////////////////
vec_set(temp.x,temp_target.x);
vec_sub(temp.x, my.x);
vec_to_angle(new_angle, temp.x);
if (ang(new_angle - my.pan) < -3)
{
my.pan -= rot_speed * time_step;
}
else
{
if (abs(ang(new_angle - my.pan)) > 3)
{
my.pan += rot_speed * time_step;
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
my.tilt=0;
c_move (my, vector(12*time_step,0 , -2), nullvector, IGNORE_PASSABLE | GLIDE);
ent_animate(my, "run", anim_percentage, ANM_CYCLE);
anim_percentage += 10 * time_step;
}
else
{
ent_animate(my, "stand", anim_percentage, ANM_CYCLE);
anim_percentage += 2 * time_step;
}
// camera code
camera.x = player.x - 300 * cos(player.pan);
camera.y = player.y - 300 * sin(player.pan); // use the same value (250) here
camera.z = player.z + 700; // place the camera above the player, play with this value
//camera.tilt = -20; // look down at the player
camera.arc = 90;
//camera.tilt = -20; // look down at the player
camera.tilt = -60; // look down at the player
//camera.pan = player.pan;
camera.pan = player.pan;
wait (1);
}
}