From: hgn Date: Mon, 10 Oct 2022 20:18:36 +0000 (+0100) Subject: add jumping X-Git-Url: https://harrygodden.com/git/?a=commitdiff_plain;ds=sidebyside;h=da929c58442de91be106438ebf2f2daabf7f2430;p=carveJwlIkooP6JGAAIwe30JlM.git add jumping --- diff --git a/main.c b/main.c index 0d4ee25..3cee76a 100644 --- a/main.c +++ b/main.c @@ -139,7 +139,11 @@ static void render_main_game(void) m4x4f world_4x4; m4x3_expand( player.camera_inverse, world_4x4 ); - gpipeline.fov = freecam? 60.0f: 125.0f; /* 120 */ + static float fov = 97.0f; + float fov_target = player.phys.on_board? 125.0f: 108.0f; + fov = vg_lerpf( fov, fov_target, vg.time_delta * 2.0f ); + + gpipeline.fov = freecam? 60.0f: fov; /* 120 */ m4x4_projection( vg.pv, gpipeline.fov, (float)vg.window_x / (float)vg.window_y, 0.02f, 2100.0f ); diff --git a/models_src/ch_new.mdl b/models_src/ch_new.mdl index 0a9f1d7..df1e23c 100644 Binary files a/models_src/ch_new.mdl and b/models_src/ch_new.mdl differ diff --git a/models_src/mp_dev.mdl b/models_src/mp_dev.mdl index c5150fa..8b89f00 100644 Binary files a/models_src/mp_dev.mdl and b/models_src/mp_dev.mdl differ diff --git a/player.h b/player.h index 25054e0..57a8628 100644 --- a/player.h +++ b/player.h @@ -27,6 +27,7 @@ static float k_steer_air_lerp = 0.3f, k_pump_force = 0.0f, k_downforce = 5.0f, + k_walk_downforce = 8.0f, k_jump_charge_speed = (1.0f/1.0f), k_jump_force = 5.0f, k_pitch_limit = 1.5f, @@ -113,7 +114,8 @@ static struct gplayer *anim_push, *anim_push_reverse, *anim_ollie, *anim_ollie_reverse, *anim_grabs, *anim_stop, - *anim_walk, *anim_run, *anim_idle; + *anim_walk, *anim_run, *anim_idle, + *anim_jump; u32 id_hip, id_ik_hand_l, diff --git a/player_animation.h b/player_animation.h index 6f19b83..72bac77 100644 --- a/player_animation.h +++ b/player_animation.h @@ -9,6 +9,18 @@ static void player_animate_offboard(void) { + { + float fly = player.phys.in_air, + rate; + + if( player.phys.in_air ) + rate = 2.4f; + else + rate = 9.0f; + + player.ffly = vg_lerpf( player.ffly, fly, rate*vg.time_delta ); + } + struct player_phys *phys = &player.phys; mdl_keyframe apose[32], bpose[32]; @@ -19,16 +31,22 @@ static void player_animate_offboard(void) t = player.walk_timer, l = vg_get_axis("grabl") * 0.5f + 0.5f; + /* walk/run */ skeleton_sample_anim( sk, player.mdl.anim_walk, t*walk_norm, apose ); skeleton_sample_anim( sk, player.mdl.anim_run, t*run_norm, bpose ); skeleton_lerp_pose( sk, apose, bpose, l, apose ); + /* idle */ float idle_walk = vg_minf(l * 10.0f, 1.0f); skeleton_sample_anim( sk, player.mdl.anim_idle, vg.time*0.1f, bpose ); skeleton_lerp_pose( sk, apose, bpose, 1.0f-idle_walk, apose ); + /* air */ + skeleton_sample_anim( sk, player.mdl.anim_jump, vg.time*0.6f, bpose ); + skeleton_lerp_pose( sk, apose, bpose, player.ffly, apose ); + skeleton_apply_pose( &player.mdl.sk, apose, k_anim_apply_defer_ik ); skeleton_apply_ik_pass( &player.mdl.sk ); skeleton_apply_pose( &player.mdl.sk, apose, k_anim_apply_deffered_only ); diff --git a/player_model.h b/player_model.h index 20e5c0a..f2b375a 100644 --- a/player_model.h +++ b/player_model.h @@ -68,7 +68,8 @@ static void player_load_model( const char *name ) { "grabs", &temp.anim_grabs }, { "walk", &temp.anim_walk }, { "run", &temp.anim_run }, - { "idle_cycle", &temp.anim_idle } + { "idle_cycle", &temp.anim_idle }, + { "jump", &temp.anim_jump } }; for( int i=0; iin_air = len==0?1:0; + + if( !phys->in_air ) + { + float const DOWNFORCE = -k_walk_downforce*VG_TIMESTEP_FIXED; + v3_muladds( phys->rb.v, (v3f){0.0f,-1.0f,0.0f}, DOWNFORCE, phys->rb.v ); + + if( vg_get_button("jump") ) + { + phys->rb.v[1] = 5.0f; + } + } v3_zero( phys->rb.w ); q_axis_angle( phys->rb.q, (v3f){0.0f,1.0f,0.0f}, -player.angles[0] ); @@ -374,7 +385,10 @@ static void player_walk_physics(void) new_vel = vg_minf( zvel + amt, speed ), diff = new_vel - vg_minf( zvel, speed ); - v3_muladds( phys->rb.v, forward_dir, diff, phys->rb.v ); + if( !phys->in_air ) + { + v3_muladds( phys->rb.v, forward_dir, diff, phys->rb.v ); + } /* TODO move */ float walk_norm = 30.0f/(float)player.mdl.anim_walk->length, @@ -387,9 +401,12 @@ static void player_walk_physics(void) { player.walk_timer = 0.0f; } - - phys->rb.v[0] *= 1.0f - (VG_TIMESTEP_FIXED * k_walk_friction); - phys->rb.v[2] *= 1.0f - (VG_TIMESTEP_FIXED * k_walk_friction); + + if( !phys->in_air ) + { + phys->rb.v[0] *= 1.0f - (VG_TIMESTEP_FIXED * k_walk_friction); + phys->rb.v[2] *= 1.0f - (VG_TIMESTEP_FIXED * k_walk_friction); + } } /* diff --git a/player_ragdoll.h b/player_ragdoll.h index be75064..28776c3 100644 --- a/player_ragdoll.h +++ b/player_ragdoll.h @@ -3,7 +3,7 @@ #include "player.h" -static float k_ragdoll_floatyiness = 40.0f, +static float k_ragdoll_floatyiness = 20.0f, k_ragdoll_floatydrag = 1.0f; /*