if( w->state.activity != k_walk_activity_immobile )
player_look( player, player->angles );
- if( w->state.outro_anim )
- {
+ if( w->state.outro_anim ){
float outro_length = (float)w->state.outro_anim->length /
w->state.outro_anim->rate,
outro_time = vg.time - w->state.outro_start_time;
- if( outro_time >= outro_length )
- {
+ if( outro_time >= outro_length ){
w->state.outro_anim = NULL;
- if( w->state.outro_type == k_walk_outro_drop_in )
- {
+ if( w->state.outro_type == k_walk_outro_drop_in ){
player_walk_drop_in_to_skate( player );
}
- else if( w->state.outro_type == k_walk_outro_jump_to_air )
- {
+ else if( w->state.outro_type == k_walk_outro_jump_to_air ){
player_walk_generic_to_skate( player, k_skate_activity_air, 0.0f );
}
- else
- {
+ else{
player_walk_generic_to_skate( player,
k_skate_activity_ground, 1.0f );
}
return;
}
}
- else if( vg_input_button_down( player->input_use ) )
- {
- if( w->state.activity == k_walk_activity_ground )
- {
- if( player_walk_scan_for_drop_in( player ) )
- {
- w->state.outro_type = k_walk_outro_drop_in;
- w->state.outro_anim = w->anim_drop_in;
- w->state.outro_start_time = vg.time;
- w->state.activity = k_walk_activity_immobile;
-
- struct player_avatar *av = player->playeravatar;
- m4x3_mulv( av->sk.final_mtx[ av->id_ik_foot_r ],
- av->sk.bones[ av->id_ik_foot_r ].co,
- w->state.drop_in_foot_anchor );
+ else if( vg_input_button_down( player->input_use ) ){
+ if( v3_dist2( player->rb.co, gzoomer.obj.rb.co ) <= 4.0f*4.0f ){
+ player->subsystem = k_player_subsystem_drive;
+ }
+ else{
+ if( w->state.activity == k_walk_activity_ground ){
+ if( player_walk_scan_for_drop_in( player ) ){
+ w->state.outro_type = k_walk_outro_drop_in;
+ w->state.outro_anim = w->anim_drop_in;
+ w->state.outro_start_time = vg.time;
+ w->state.activity = k_walk_activity_immobile;
+
+ struct player_avatar *av = player->playeravatar;
+ m4x3_mulv( av->sk.final_mtx[ av->id_ik_foot_r ],
+ av->sk.bones[ av->id_ik_foot_r ].co,
+ w->state.drop_in_foot_anchor );
+ }
+ else{
+ w->state.outro_type = k_walk_outro_regular;
+ w->state.outro_anim = w->anim_intro;
+ w->state.outro_start_time = vg.time;
+ w->state.activity = k_walk_activity_lockedmove;
+
+ if( player_xyspeed2(player) < 0.1f * 0.1f )
+ q_mulv( player->rb.q, (v3f){0.0f,0.0f,1.6f}, player->rb.v );
+ }
}
- else
- {
- w->state.outro_type = k_walk_outro_regular;
- w->state.outro_anim = w->anim_intro;
+ else{
+ w->state.outro_type = k_walk_outro_jump_to_air;
+ w->state.outro_anim = w->anim_jump_to_air;
w->state.outro_start_time = vg.time;
- w->state.activity = k_walk_activity_lockedmove;
-
- if( player_xyspeed2(player) < 0.1f * 0.1f )
- q_mulv( player->rb.q, (v3f){0.0f,0.0f,1.6f}, player->rb.v );
+ return;
}
}
- else
- {
- w->state.outro_type = k_walk_outro_jump_to_air;
- w->state.outro_anim = w->anim_jump_to_air;
- w->state.outro_start_time = vg.time;
- return;
- }
}
}
struct player_walk *w = &player->_walk;
v3_copy( player->rb.co, w->state.prev_pos );
+ enum walk_activity prev_state = w->state.activity;
+
if( w->state.activity == k_walk_activity_immobile )
return;
v2_normalize_clamp( walk );
w->move_speed = v2_length( walk );
+ world_instance *world = get_active_world();
/*
* Collision detection
*/
- world_instance *world = get_active_world();
len = rb_capsule__scene( mtx, &w->collider, NULL,
&world->rb_geo.inf.scene, manifold );
w->surface = k_surface_prop_concrete;
- for( int i=0; i<len; i++ )
- {
+ for( int i=0; i<len; i++ ){
struct contact *ct = &manifold[i];
rb_debug_contact( ct );
- if( player_walk_normal_standable( player, ct->n ) )
- {
+ if( player_walk_normal_standable( player, ct->n ) ){
if( w->state.activity != k_walk_activity_lockedmove )
w->state.activity = k_walk_activity_ground;
/* jump */
if( player->input_jump->button.value ){
+ float d = v3_dot( player->basis[1], player->rb.v );
+ v3_muladds( player->rb.v, player->basis[1], -d, player->rb.v );
v3_muladds( player->rb.v, player->basis[1], 5.0f, player->rb.v );
w->state.activity = k_walk_activity_air;
+ prev_state = k_walk_activity_air;
accel_speed = k_walk_air_accel;
nominal_speed = k_airspeed;
}
}
}
- /*
- * Depenetrate
- */
- v3f dt;
- rb_depenetrate( manifold, len, dt );
- v3_add( dt, player->rb.co, player->rb.co );
-
- /* TODO: Stepping......
- *
- * ideas; walkgrid style steps
- */
-#if 0
- if( w->state.activity == k_walk_activity_ground )
- {
- /* step */
+ /* stepping */
+ if( w->state.activity == k_walk_activity_ground||
+ prev_state == k_walk_activity_ground ){
float max_dist = 0.4f;
v3f pa, pb;
v3_copy( player->rb.co, pa );
- pa[1] += w->collider.radius + max_dist;
-
- v3_muladds( pa, (v3f){0.0f,1.0f,0.0f}, -max_dist * 2.0f, pb );
+ v3_muladds( pa, player->basis[1], w->collider.radius + max_dist, pa );
+ v3_muladds( pa, player->basis[1], -max_dist * 2.0f, pb );
vg_line( pa, pb, 0xff000000 );
v3f n;
float t;
- if( spherecast_world( pa, pb, w->collider.radius, &t, n ) != -1 )
- {
- if( player_walk_normal_standable( n ) )
- {
+ if( spherecast_world( world, pa, pb, w->collider.radius, &t, n ) != -1 ){
+ if( player_walk_normal_standable( player, n ) ){
v3_lerp( pa, pb, t, player->rb.co );
- player->rb.co[1] -= w->collider.radius;
+ v3_muladds( player->rb.co, player->basis[1],
+ -w->collider.radius - k_penetration_slop,
+ player->rb.co );
+ w->state.activity = k_walk_activity_ground;
+
+ float d = -v3_dot(n,player->rb.v),
+ g = -k_gravity * k_rb_delta;
+ v3_muladds( player->rb.v, n, d, player->rb.v );
+ v3_muladds( player->rb.v, player->basis[1], g, player->rb.v );
}
}
}
-#endif
+ /*
+ * Depenetrate
+ */
+ v3f dt;
+ rb_depenetrate( manifold, len, dt );
+ v3_add( dt, player->rb.co, player->rb.co );
/* integrate */
- if( w->state.activity == k_walk_activity_air )
- {
+ if( w->state.activity == k_walk_activity_air ){
v3_muladds( player->rb.v, player->basis[1], -k_gravity*k_rb_delta,
player->rb.v );
}
float movedist = v3_length( movedelta );
- if( movedist > 0.3f )
- {
+ if( movedist > 0.3f ){
float t, sr = w->collider.radius-0.04f;
v3f n;
- if( spherecast_world( world, lwr_prev, lwr_now, sr, &t, n ) != -1 )
- {
+ if( spherecast_world( world, lwr_prev, lwr_now, sr, &t, n ) != -1 ){
v3_lerp( lwr_prev, lwr_now, vg_maxf(0.01f,t), player->rb.co );
player->rb.co[1] -= w->collider.radius;
rb_update_transform( &player->rb );
w->state_gate_storage = w->state;
player__pass_gate( player, gate );
}
+ rb_update_transform( &player->rb );
+}
+
+VG_STATIC void player__walk_restore( player_instance *player )
+{
+ struct player_walk *w = &player->_walk;
+ w->state = w->state_gate_storage;
}
VG_STATIC void player__walk_post_update( player_instance *player )
m3x3_copy( player->rb.to_world, mtx );
v3_add( player->rb.co, player->basis[1], mtx[3] );
- float substep = vg_clampf( vg.accumulator / k_rb_delta, 0.0f, 1.0f );
+ float substep = vg.time_fixed_extrapolate;
v3_muladds( mtx[3], player->rb.v, k_rb_delta*substep, mtx[3] );
debug_capsule( mtx, w->collider.radius, w->collider.height, VG__YELOW );
"metal" }
[w->surface] );
- if( w->state.outro_anim )
- {
+ if( w->state.outro_anim ){
float outro_length = (float)w->state.outro_anim->length /
w->state.outro_anim->rate,
outro_time = vg.time - w->state.outro_start_time;
rb_update_transform( &player->rb );
}
+VG_STATIC void player__walk_reset( player_instance *player, ent_spawn *rp )
+{
+ struct player_walk *w = &player->_walk;
+ w->state.activity = k_walk_activity_air;
+ w->state.outro_type = k_walk_outro_none;
+ w->state.outro_anim = NULL;
+ w->state.outro_start_time = 0.0;
+}
+
#endif /* PLAYER_DEVICE_WALK_H */