Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: sliding collisions #911

Merged
merged 2 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/core/elements/slippery_seaweed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub fn update(
.actor_collisions(p_ent)
.contains(&seaweed_ent)
{
state.current = "core::incapacitated".into();
state.current = *incapacitated::ID;
continue;
}
}
Expand Down
20 changes: 15 additions & 5 deletions src/core/player/state/states/crouch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ pub fn player_state_transition(
&mut bodies,
&mut transforms,
)) {
let meta_handle = player_inputs.players[player_idx.0 as usize].selected_player;
let player_input = &player_inputs.players[player_idx.0 as usize];
let meta_handle = player_input.selected_player;
let meta = assets.get(meta_handle);

// Reset the body size and position if we stop sliding
Expand All @@ -33,7 +34,10 @@ pub fn player_state_transition(
body.shape = ColliderShape::Rectangle {
size: meta.body_size,
};
transform.translation += (meta.body_size.y - meta.slide_body_size.y) / 2.0;
let offset = (meta.body_size.y - meta.slide_body_size.y) / 2.0;
let direction = player_input.control.move_direction.x.signum();
transform.translation.x += offset * direction;
transform.translation.y += offset;
}
}
}
Expand Down Expand Up @@ -69,7 +73,8 @@ pub fn handle_player_state(
if state.current != *ID {
continue;
}
let meta_handle = player_inputs.players[player_idx.0 as usize].selected_player;
let player_input = &player_inputs.players[player_idx.0 as usize];
let meta_handle = player_input.selected_player;
let meta = assets.get(meta_handle);

if body.velocity.x == 0.0 {
Expand All @@ -79,7 +84,10 @@ pub fn handle_player_state(
body.shape = ColliderShape::Rectangle {
size: meta.body_size,
};
transform.translation += (meta.body_size.y - meta.slide_body_size.y) / 2.0;
let offset = (meta.body_size.y - meta.slide_body_size.y) / 2.0;
let direction = player_input.control.move_direction.x.signum();
transform.translation.x += offset * direction;
transform.translation.y += offset;
}
}
} else if let ColliderShape::Rectangle { size } = &body.shape {
Expand All @@ -89,7 +97,9 @@ pub fn handle_player_state(
body.shape = ColliderShape::Rectangle {
size: meta.slide_body_size,
};
transform.translation -= (meta.body_size.y - meta.slide_body_size.y) / 2.0;
let offset = (meta.body_size.y - meta.slide_body_size.y) / 2.0;
transform.translation.x -= offset;
transform.translation.y -= offset;
}
}

Expand Down
Loading