action players_code() {
var anim_percentage; // animation percentage
VECTOR movement_speed; // player's movement speed
VECTOR tempcamera;
var distance_to_ground; // the distance between player's origin and the ground
var camdist = 230;
var camheight = 70;
VECTOR temp;
VECTOR* temp2;
player = my; // I'm the player
while (1) {
camera.x=player.x - camdist * cos(player.pan);
camera.y=player.y - camdist * sin(player.pan);
camera.z = player.z + camheight;
camera.pan=player.pan;
camera.tilt = -10;
//THIS PART CAUSEs FLICKERING WHY????!!!
//vec_set(camera.x,vector(-180,0,50));
//vec_rotate(camera.x,player.pan);
//vec_add(camera.x,player.x);
//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);
}
}