action players_code() {
var anim_percentage; // animation percentage
VECTOR movement_speed; // player's movement speed
VECTOR tempcam;
var distance_to_ground; // the distance between player's origin and the ground
VECTOR temp;
player = my; // I'm the player
while (1) {
//THIS PART CAUSEs FLICKERING WHY????!!!
vec_set(tempcam.x,vector(-180,0,50));
vec_rotate(tempcam.x,player.pan);
vec_add(tempcam.x,player.x);
vec_set(camera.x,tempcam);
camera.pan = player.pan;
camera.tilt = -15;
//THAT^ PART CAUSEs FLICKERING WHY????!!!
my.pan += 6 * (key_a - key_d) * time_step; // rotate the player using the "A" and "D" keys
vec_set (temp.x, my.x); // copy player's position to temp
temp.z -= 5000; // set temp.z 5000 quants below player's origin
distance_to_ground = c_trace (my.x, temp.x, IGNORE_ME | USE_BOX);
movement_speed.x = 10 * (key_w - key_s) * time_step; // move the player using "W" and "S"
movement_speed.y = 0; // don't move sideways
movement_speed.z = - (distance_to_ground - 17); // 17 = experimental value
movement_speed.z = maxv(-35 * time_step, movement_speed.z); // 35 = falling speed
c_move (my, movement_speed.x, nullvector, GLIDE); // move the player
if ((key_w == OFF) && (key_s == OFF)) {
ent_animate(my, "Standa", anim_percentage, ANM_CYCLE); // play the "stand" animation
} else {
ent_animate(my, "Walka", anim_percentage, ANM_CYCLE); // play the "walk" animation
}
anim_percentage += 8 * time_step; // 5 = animation speed
wait (1);
}
}