+ float min_a = 0.70710678118654752f;
+ ray_hit *candidate = NULL;
+
+ if( sample_count >= 2 )
+ {
+ for( int i=0; i<sample_count-1; i++ )
+ {
+ ray_hit *s0 = &samples[i],
+ *s1 = &samples[i+1];
+
+ float a = v3_dot( s0->normal, s1->normal );
+
+ if( (a < min_a) && (a >= -0.1f) && (s0->normal[1]>s1->normal[1]) )
+ {
+ min_a = a;
+ candidate = s0;
+ }
+ }
+ }
+
+ if( candidate )
+ {
+ v4f pa, pb, pc;
+
+ ray_hit *s0 = candidate,
+ *s1 = candidate+1;
+
+ vg_line( s0->pos, s1->pos, VG__WHITE );
+
+ v3_copy( s0->normal, pa );
+ v3_copy( s1->normal, pb );
+ v3_cross( player->rb.to_world[1], dir, pc );
+ v3_normalize( pc );
+
+ pa[3] = v3_dot( pa, s0->pos );
+ pb[3] = v3_dot( pb, s1->pos );
+ pc[3] = v3_dot( pc, player->rb.co );
+
+ v3f edge;
+ if( plane_intersect3( pa, pb, pc, edge ) )
+ {
+ v3_copy( edge, w->state.drop_in_target );
+ v3_copy( s1->normal, w->state.drop_in_normal );
+ v3_copy( player->rb.co, w->state.drop_in_start );
+
+ w->state.drop_in_start_angle = player_get_heading_yaw( player );
+ w->state.drop_in_angle = atan2f( w->state.drop_in_normal[0],
+ w->state.drop_in_normal[2] );
+
+ /* TODO: scan multiple of these? */
+ v3f oco;
+ v4f oq;
+ player_walk_drop_in_overhang_transform( player, 1.0f, oco, oq );
+
+ v3f va = {0.0f,0.0f,-k_board_length - 0.3f},
+ vb = {0.0f,0.0f, k_board_length + 0.3f};
+
+ q_mulv( oq, va, va );
+ q_mulv( oq, vb, vb );
+ v3_add( oco, va, va );
+ v3_add( oco, vb, vb );
+
+ v3f v0;
+ v3_sub( vb, va, v0 );
+ v3_normalize( v0 );
+
+ ray_hit ray;
+ ray.dist = k_board_length*2.0f + 0.6f;
+
+ if( ray_world( world, va, v0, &ray ) )
+ {
+ vg_line( va, vb, VG__RED );
+ vg_line_point( ray.pos, 0.1f, VG__RED );
+ vg_error( "invalidated\n" );
+ return 0;
+ }
+
+ v3_muls( v0, -1.0f, v0 );
+ if( ray_world( world, vb, v0, &ray ) )
+ {
+ vg_line( va, vb, VG__RED );
+ vg_line_point( ray.pos, 0.1f, VG__RED );
+ vg_error( "invalidated\n" );
+ return 0;
+ }
+
+ player_walk_drop_in_vector( player, player->rb.v );
+ return 1;
+ }
+ else
+ {
+ vg_error( "failed to find intersection of drop in\n" );
+ }
+ }
+
+ return 0;
+}
+
+VG_STATIC void player__walk_pre_update( player_instance *player )
+{
+ struct player_walk *w = &player->_walk;
+
+ if( !player->immobile )
+ player_look( player, player->angles );
+
+ 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 ){
+ w->state.outro_anim = NULL;
+ 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 ){
+ player_walk_generic_to_skate( player, k_skate_activity_air, 0.0f );
+ }
+ else{
+ player_walk_generic_to_skate( player,
+ k_skate_activity_ground, 1.0f );
+ }
+
+ return;
+ }
+ }
+ else if( button_down( k_srbind_use ) && !player->immobile ){
+ if( v3_dist2( player->rb.co, gzoomer.obj.rb.co ) <= 4.0f*4.0f ){
+ player->subsystem = k_player_subsystem_drive;
+ }
+ else{
+ struct player_board *board =
+ addon_cache_item_if_loaded( k_addon_type_board,
+ player->board_view_slot );
+
+ if( !board ) return;
+
+ 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;
+ player->immobile = 1;
+
+ 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_jump_to_air;
+ w->state.outro_anim = w->anim_jump_to_air;
+ w->state.outro_start_time = vg.time;
+ return;
+ }
+ }
+ }
+ else if( button_down( k_srbind_jump ) && !player->immobile ){
+ w->state.jump_queued = 1;
+ w->state.jump_input_time = vg.time;