action my_action()
{
VECTOR player_distance;
var pose_speed = 0;
var walk_speed = 0; // stores robot's walking animation
var turn_speed = 0;
var reload_speed = 0;
ANGLE bone_angle; // a vector that holds the pan, tilt and roll angles
player=me;
var cycle=0;
var key_pressed=0;
var a =200;
var b =200;
while(1)
{
camera.arc = 70;
camera.clip_near = 0;
camera.pan = player.pan;
camera.tilt=bone_angle.tilt;
camera.roll=0;
camera.x=player.x -55 * cos(player.pan);
camera.y=player.y -55 * sin(player.pan);
camera.z=player.z+40;
ent_animate(my, NULL, 0, 0); // reset all the animations
pose_speed += 2 * time_step; // increase walk_speed, "2" sets the animation speed
ent_animate(my, "wpose", pose_speed, ANM_CYCLE); // animate the model (use "walk")
bone_angle.pan = (mouse_pos.x - screen_size.x / 2) / 10; // changes pan from -40 to +40 degrees
bone_angle.tilt = (screen_size.y / 2 - mouse_pos.y) / 10; // changes tilt from -30 to +30 degrees
bone_angle.roll = 0; // no need to change the roll angle for this bone
ent_bonereset(my,"Spine");
ent_bonerotate(my,"Spine", bone_angle); // rotate the bone named "CA4"
if (key_r && key_pressed==0) // reload
{
key_pressed=1;
}
if(key_pressed)
{
ent_animate(my, NULL, 0, 0); // reset all the animations
reload_speed += 5 * time_step; // then increase turn_speed
ent_animate(my, "reload", reload_speed, ANM_ADD); // animate the model (use "turn")
if(reload_speed>=100)
{
key_pressed=0;
reload_speed=0;
}
}
if(key_a||key_d) //Turn
{
my.pan+=5*(key_a-key_d)*time_step;
// ent_animate(my, NULL, 0, 0); // reset all the animations
turn_speed += 5 * time_step; // then increase turn_speed
ent_animate(my, "walk", turn_speed, ANM_ADD); // animate the model (use "turn")
if(turn_speed>=100){turn_speed=0;}
}
if(key_w||key_s) //Move
{
player_distance.x = (key_w - key_s) * 5 * time_step;
player_distance.y = 0;
player_distance.z = 0;
c_move (my, player_distance, nullvector, GLIDE | IGNORE_PASSABLE);
// ent_animate(my, NULL, 0, 0); // reset all the animations
walk_speed += 10 * time_step; // then increase turn_speed
ent_animate(my, "walk", walk_speed, ANM_ADD); // animate the model (use "turn")
if(walk_speed>=100){walk_speed=0;}
}
wait(1);
}
}