Slow down player when crouching
Changelog: - Add friction coefficient to transform component and its update systemscene_man
parent
8d94943547
commit
45972d6416
|
@ -34,6 +34,7 @@ typedef struct _CTransform_t
|
|||
Vector2 position;
|
||||
Vector2 velocity;
|
||||
Vector2 accel;
|
||||
Vector2 fric_coeff;
|
||||
}CTransform_t;
|
||||
|
||||
typedef struct _CMovementState_t
|
||||
|
|
|
@ -319,6 +319,7 @@ void init_level_scene(LevelScene_t *scene)
|
|||
// insert level scene systems
|
||||
sc_array_add(&scene->scene.systems, &player_movement_input_system);
|
||||
sc_array_add(&scene->scene.systems, &player_bbox_update_system);
|
||||
sc_array_add(&scene->scene.systems, &friction_coefficient_update_system);
|
||||
sc_array_add(&scene->scene.systems, &global_external_forces_system);
|
||||
sc_array_add(&scene->scene.systems, &movement_update_system);
|
||||
sc_array_add(&scene->scene.systems, &update_tilemap_system);
|
||||
|
|
|
@ -258,6 +258,10 @@ void player_movement_input_system(Scene_t* scene)
|
|||
p_ctransform->accel = Vector2Scale(Vector2Normalize(p_pstate->player_dir), MOVE_ACCEL/1.2);
|
||||
}
|
||||
|
||||
if (p_pstate->is_crouch & 1)
|
||||
{
|
||||
p_ctransform->accel = Vector2Scale(p_ctransform->accel, 0.5);
|
||||
}
|
||||
// Short Hop
|
||||
// Jumped check is needed to make sure it is applied on jumps, not generally
|
||||
// One issue caused is lower velocity in water
|
||||
|
@ -496,6 +500,40 @@ void tile_collision_system(Scene_t *scene)
|
|||
}
|
||||
}
|
||||
|
||||
void friction_coefficient_update_system(Scene_t *scene)
|
||||
{
|
||||
CTransform_t* p_ct;
|
||||
unsigned long ent_idx;
|
||||
sc_map_foreach(&scene->ent_manager.component_map[CTRANSFORM_COMP_T], ent_idx, p_ct)
|
||||
{
|
||||
Entity_t *p_ent = get_entity(&scene->ent_manager, ent_idx);
|
||||
CMovementState_t* p_mstate = get_component(&scene->ent_manager, p_ent, CMOVEMENTSTATE_T);
|
||||
|
||||
|
||||
// Friction
|
||||
if (p_mstate->water_state & 1)
|
||||
{
|
||||
// Apply water friction
|
||||
// Consistent in all direction
|
||||
p_ct->fric_coeff = (Vector2){-5.5, -5.5};
|
||||
}
|
||||
else
|
||||
{
|
||||
// For game feel, y is set to air resistance only
|
||||
// x is set to ground resistance (even in air)
|
||||
// If not, then player is can go faster by bunny hopping
|
||||
// which is fun but not quite beneficial here
|
||||
p_ct->fric_coeff = (Vector2){-3.3, -1};
|
||||
}
|
||||
|
||||
CPlayerState_t* p_pstate = get_component(&scene->ent_manager, p_ent, CPLAYERSTATE_T);
|
||||
if (p_pstate != NULL && (p_pstate->is_crouch & 1))
|
||||
{
|
||||
p_ct->fric_coeff.x -= 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void global_external_forces_system(Scene_t *scene)
|
||||
{
|
||||
LevelSceneData_t *data = (LevelSceneData_t *)scene->scene_data;
|
||||
|
@ -525,25 +563,12 @@ void global_external_forces_system(Scene_t *scene)
|
|||
}
|
||||
p_ctransform->accel = Vector2Add(p_ctransform->accel, GRAVITY);
|
||||
}
|
||||
|
||||
// Friction
|
||||
if (p_mstate->water_state & 1)
|
||||
{
|
||||
// Apply water friction
|
||||
// Consistent in all direction
|
||||
p_ctransform->accel = Vector2Add(
|
||||
p_ctransform->accel,
|
||||
Vector2Scale(p_ctransform->velocity, -5.5)
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
// For game feel, y is set to air resistance only
|
||||
// x is set to ground resistance (even in air)
|
||||
// If not, then player is can go faster by bunny hopping
|
||||
// which is fun but not quite beneficial here
|
||||
p_ctransform->accel.x += p_ctransform->velocity.x * -3.3;
|
||||
p_ctransform->accel.y += p_ctransform->velocity.y * -1;
|
||||
}
|
||||
p_ctransform->accel = Vector2Add(
|
||||
p_ctransform->accel,
|
||||
Vector2Multiply(p_ctransform->fric_coeff, p_ctransform->velocity)
|
||||
);
|
||||
|
||||
|
||||
// Zero out acceleration for contacts with sturdy entites and tiles
|
||||
|
|
|
@ -7,6 +7,7 @@ void term_level_scene_data(LevelSceneData_t *data);
|
|||
void player_movement_input_system(Scene_t* scene);
|
||||
void player_bbox_update_system(Scene_t *scene);
|
||||
void tile_collision_system(Scene_t *scene);
|
||||
void friction_coefficient_update_system(Scene_t *scene);
|
||||
void global_external_forces_system(Scene_t *scene);
|
||||
void movement_update_system(Scene_t* scene);
|
||||
void player_ground_air_transition_system(Scene_t* scene);
|
||||
|
|
Loading…
Reference in New Issue