////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////
VECTOR ladder_x;
VECTOR player_diff;
VECTOR temp;
////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////
var movement_mode = 0;
var player_feet_height = 32; //the distance from the origin to the feet of the player
var z_force = 0;
var jump_z;
////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////
#define animdist skill20
////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////
function detect_edge()
{
my.animdist = 0;
if (movement_mode == 0)
{
vec_set(temp,my.x); //scan in front of player to see if there is a climbable wall
temp.x += 30 * cos(my.pan);
temp.y += 30 * sin(my.pan);
temp.z = my.z;
result = c_trace(my.x,temp,IGNORE_ME|IGNORE_SPRITES|IGNORE_MODELS|SCAN_TEXTURE);
vec_set(temp,my.x);
temp.z -= 4000; // calculate a position 4000 quants below the player
// set a trace mode for using the player's hull, and detecting map entities and level surfaces only
result = c_trace(my.x,temp,IGNORE_ME|IGNORE_SPRITES|IGNORE_MODELS|USE_BOX);// subtract vertical distance to ground
if (result <= 3)
{
// in the air?
if ((result < 1.3) && (result > -1.3) && (result > 0.5) && (result < -0.5))
{
//change the value 1.5 to change how high steps he can climb, make it no higher than 3
my.skill13 = 0;
}
vec_set(temp,my.x);
temp.z -= 4000; // calculate a position 4000 quants below the player
result = c_trace(my.x,temp,IGNORE_ME|IGNORE_SPRITES|IGNORE_MODELS|USE_BOX);
// subtract vertical distance to ground
z_force = -1 * result;
}
else
{
if ((result <= 3) && (my.animdist > 20))
{
if ((result < 1.3) && (result > -1.3) && (result > 0.5) && (result < -0.5))
{
//change the value 1.5 to change how high steps he can climb, make it no higher than 3
my.skill13 = 0;
}
vec_set(temp,my.x);
temp.z -= 4000; // calculate a position 4000 quants below the player
result = c_trace(my.x,temp,IGNORE_ME|IGNORE_SPRITES|IGNORE_MODELS|USE_BOX);// subtract vertical distance to ground
z_force = -1 * result;
}
}
if ((key_w == 1) || (key_s == 1) || (key_d == 1) || (key_a == 1))
{
if (key_shift == 0)
{
ent_animate(my,"run",my.animdist,ANM_CYCLE);
my.animdist += 10 * time_step;
}
else
{
ent_animate(my,"walk",my.animdist,ANM_CYCLE);
my.animdist += 9 * time_step;
}
}
else
{
ent_animate(my,"stand",my.animdist,ANM_CYCLE);
my.animdist += 3 * time_step;
}
my.skill13 = 0.5*z_force + maxv(1-0.5*0.7,0)*my.skill13; // calculate vertical speed, replace 0.3 with time to convert to the old equation
jump_z = time_step * my.skill13; // distance down
player_diff.z = jump_z;
c_move(my,player_diff, nullvector,IGNORE_PASSABLE|GLIDE);
//center_check();
//update_views();
}
if (movement_mode == 2)
{
//pulling yourself up onto a ledge
my.z += 5 * time_step;
player_diff.x = 1;
player_diff.y = 0;
player_diff.z = 0;
c_move(my,player_diff.x,nullvector,IGNORE_PASSABLE|GLIDE);
vec_set(temp,my.x); //scan in front of player to see if there is a climbable wall
temp.x += 30 * cos(my.pan);
temp.y += 30 * sin(my.pan);
temp.z = my.z - player_feet_height; //set the value 32 to the distance to the models feet
if(c_trace(my.x,temp,IGNORE_ME|IGNORE_SPRITES|IGNORE_MODELS) == 0)
{
movement_mode = 3;
vec_set(ladder_x.x,my.x);
}
ent_animate(my,"walk",my.animdist,ANM_CYCLE); // edge climb animation here
my.animdist += 9 * time_step; // 9 is climbing speed
//center_check();
//update_views();
}
if (movement_mode == 3)
{
//moving a little bit forward so that player doesn't fall down
player_diff.x = 3 * time_step;
player_diff.y = 0;
vec_set(temp,my.x);
temp.z -= 4000; // calculate a position 4000 quants below the player
// set a trace mode for using the player's hull, and detecting map entities and level surfaces only
result = c_trace(my.x,temp,IGNORE_ME|IGNORE_SPRITES|IGNORE_MODELS|USE_BOX);// subtract vertical distance to ground
player_diff.z = 0;
if (result < 4) { player_diff.z = -0.2 * result; }
if(vec_dist(my.x,ladder_x.x) > 7)
{
vec_set(temp,my.x);
temp.z -= 4000; // calculate a position 4000 quants below the player
// set a trace mode for using the player's hull, and detecting map entities and level surfaces only
result = c_trace(my.x,temp,IGNORE_ME|IGNORE_SPRITES|IGNORE_MODELS|USE_BOX);// subtract vertical distance to ground
if (result < 4) { player_diff.z = -1 * result; }
}
else
{
player_diff.z = 0;
}
c_move(my,player_diff, nullvector, IGNORE_PASSABLE|GLIDE);
if(vec_dist(my.x,ladder_x.x) > 15)
{
movement_mode = 0;
player_diff.z = 0;
//z_force = 0;
my.skill13 = 0;
}
ent_animate(my,"walk",my.animdist,ANM_CYCLE);
my.animdist += 9 * time_step;
//center_check();
//update_views();
}
}