2 registered members (AndrewAMD, Ayumi),
838
guests, and 2
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: Collision
[Re: Redeemer]
#361966
03/05/11 23:18
03/05/11 23:18
|
Joined: Sep 2006
Posts: 292
Mythran
OP
Member
|
OP
Member
Joined: Sep 2006
Posts: 292
|
So how can i add c_move in here?
Thanks
action my_player { var walk_percentage; // controls the "walk" animation speed var stand_percentage; // controls the "stand" animation speed var climb_percentage; // controls the "climb" animation speed var movement_speed; // player's movement speed player = my; // I'm the player //my.narrow = on; c_setminmax(my); my.ambient = -50; // play with the ambient value (-100...100) my.transparent = on; // the player could be transparent my.alpha = 100; // but will be opaque if the camera doesn't run into obstacles my.skill41 = my.camera_height; // store the height of the camera in relation to player's origin my.skill42 = my.camera_distance; // store the distance to the camera if (my.health == 0) {my.health = 100;} // default health points = 100 if (my.camera_height == 0) {my.camera_height = 50;} // default camera_height value = 50 if (my.camera_distance == 0) {my.camera_distance = 250;} // default camera_distance value = 250 if (my.player_speed == 0) {my.player_speed = 3;} // default player_speed = 6 if (my.player_inertia == 0) {my.player_inertia = 0.5;} // default inertia = 0.5 if (my.player_rotation_speed == 0) {my.player_rotation_speed = 3;} // default player rotation speed = 5 if (my.player_climbing_speed == 0) {my.player_climbing_speed = 5;} // default player climbing speed = 5 if (my.dist_to_ground == 0) {my.dist_to_ground = 0;} // default distance between player's feet and the ground = 6 quants if (my.pan_rotation_speed == 0) {my.pan_rotation_speed = 0.6;} // default camera rotation speed (pan) = 0.8 if (my.tilt_rotation_speed == 0) {my.tilt_rotation_speed = 5;} // default camera rotation speed (tilt) = 7 if (my.foot_step_distance == 0) {my.foot_step_distance = 59;} // default foot step distance = 59 while (my.health > 0) // as long as the player is alive { // rotate the player using the mouse, "A" and "D" or "cursor left" and "cursor right" player.pan -= my.player_rotation_speed * mouse_force.x * time - 1.1 * ((key_cul || key_a) - (key_cur || key_d)); camera.x = player.x - my.camera_distance * cos(player.pan); // keep the camera behind the player camera.y = player.y - my.camera_distance * sin(player.pan); // at the distance given by camera_distance camera.z = player.z + my.camera_height + 0.8 * sin(my.skill46 * 3.6); // and above the player; 3.6 gives the head weaving amplitude if (abs(ang(camera.pan) - ang(player.pan)) > 3) // need to rotate the camera quickly? { camera.pan += (player.pan - camera.pan) * my.pan_rotation_speed * time; // then do it! } else // no need for sudden camera rotations? { camera.pan += (player.pan - camera.pan) * my.pan_rotation_speed * 0.33 * time; // then rotate a bit slower } camera.tilt += my.tilt_rotation_speed * mouse_force.y * time; // the camera can tilt freely my.camera_distance = min (max (my.camera_distance, 5), 1000); // camera_distance can have values between 5 and 1000 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); // compute the distance to ground
my.skill22 = my.player_speed * ((key_w || key_cuu) - (key_s || key_cud)); // move the player using "W" and "S" or "cursor up" and "cursor down" my.skill21 = my.skill22 * time + max (1 - time * my.player_inertia, 0) * my.skill21; // compute speed movement_speed.x = my.skill21 * time; // time correct the speed
movement_speed.y = 0; // don't move sideways // the "space" key or the right mouse button are pressed and the player isn't jumping already? if (((key_space == on) || (mouse_right == on)) && (now_jumping == 0)) { perform_jump(); // then perform the jumping! } if (((key_space == off) && (mouse_right == off)) || (now_jumping == 0)) // space or the RMB aren't pressed anymore? { jump_height = max(0, jump_height - 12 * time); // use a smaller falling speed (15) for (potential) smaller jumps if ((jump_height == 0) && (key_space == off) && (mouse_right == off)) // the player has touched the ground? { reached_height = 0; // then allow it to jump again } } // my.dist_to_ground = 6, experimental value, puts player's feet on the ground movement_speed.z = - (distance_to_ground - my.dist_to_ground) + min (200, jump_height); movement_speed.z = min(4, movement_speed.z); // limit the movement speed on the z axis movement_speed.z = max (-20 * time, movement_speed.z); // 20 = falling speed if ((key_ctrl == on) && ((key_cuu == on) || (key_w == on))) // trying to climb up { vec_set (content_dist.x, player.x); vec_set (temp, vector(20, 0, -20)); // check the content 20 quants in front of the player, 20 quants below its origin (-20) vec_rotate(temp, vector(player.pan, 0,0)); vec_add (content_dist.x, temp.x); // content_dist is now set at player's feet, 20 quants in front of them if (content (content_dist) == content_solid) // there's a wall in front of the player? { movement_speed.z = my.player_climbing_speed * time; // then start climbing! } } my.skill47 += c_move (my, movement_speed.x, nullvector, glide); // move the player if (my.skill47 > my.foot_step_distance) // adjust my.foot_step_distance (by default, we've got a step sound every 59 quants) { if ((jump_height == 0) && (movement_speed.z == 0)) // not jumping and not falling? { snd_play(step_wav, 20, 0); // then play the foot step sound my.skill47 = 0; // reset the distance (increase the precission) } } if (jump_height == 0) // the player isn't jumping? { if ((key_w == off) && (key_s == off) && (key_cuu == off) && (key_cud == off)) // the player isn't moving? { ent_animate(my, "stand", stand_percentage, anm_cycle); // play the "stand" animation } else // the player is moving? { if ((key_ctrl == on) && (content (content_dist) == content_solid)) // climbing? { // use a real "climb" animation here; I've only got "finish_him" for this model (although it looks good enough imo) ent_animate(my, "attack", climb_percentage, anm_cycle); } else // not climbing? { ent_animate(my, "walk", walk_percentage, anm_cycle); // then play the "walk" animation } } walk_percentage += 8 * ((key_w || key_cuu) - (key_s || key_cud)) * time; // 10 = animation speed climb_percentage += 8 * time; // 10 = animation speed jump_percentage = 0; // always start jumping with the first frame } else // the player is jumping { if (ascending == 1) { jump_percentage = jump_height / 2; // playing frames 1...50 stand_percentage = 0; } else // descending, playing frames 51...100 { jump_percentage = min(100, (200 - jump_height) / 2); // limit the animation frame to 100 } ent_animate(my, "jump", jump_percentage, anm_cycle); // play the "jump" animation } stand_percentage += 0.5 * time; // 5 = animation speed avoid_obstacles(); // run the function that avoids camera collisions with the relief wait (1); } // the player is dead here my.skill40 = 0; // use skill40 to control the "death" animation while (my.skill40 < 90) // don't play all the animation frames because the result doesn't look too good { ent_animate(my, "death", my.skill40, null); my.skill40 += 2 * time; // "death" animation speed camera.roll -= 0.3 * time; // rotate the camera camera.tilt += 0.8 * time; // make it look up high in the sky wait (1); } my.passable = on; // the corpse will be passable from now on }
|
|
|
|