Skip to content

fix: block collisions on edge of block #541

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

Merged
merged 1 commit into from
Oct 31, 2024
Merged
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
7 changes: 4 additions & 3 deletions crates/hyperion/src/simulation/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ fn try_change_position(
is_within_speed_limits(**position, proposed)?;

// Only check collision if we're starting outside a block
if !has_collision(position, size, blocks) && has_collision(&proposed, size, blocks) {
if !has_block_collision(position, size, blocks) && has_block_collision(&proposed, size, blocks)
{
return Err(anyhow::anyhow!("Cannot move into solid blocks"));
}

Expand All @@ -138,7 +139,7 @@ fn is_within_speed_limits(current: Vec3, proposed: Vec3) -> anyhow::Result<()> {
Ok(())
}

fn has_collision(position: &Vec3, size: EntitySize, blocks: &Blocks) -> bool {
fn has_block_collision(position: &Vec3, size: EntitySize, blocks: &Blocks) -> bool {
use std::ops::ControlFlow;

let (min, max) = block_bounds(*position, size);
Expand Down Expand Up @@ -421,7 +422,7 @@ pub fn player_interact_block(

// todo(hack): technically players can do some crazy position stuff to abuse this probably
// let player_aabb = query.position.bounding.shrink(0.01);
let player_aabb = aabb(**query.position, *query.size).shrink(0.01);
let player_aabb = aabb(**query.position, *query.size);

let collides_player = block_state
.collision_shapes()
Expand Down