Fixed scaled terrain collisions

This commit is contained in:
Joshua Barretto 2022-08-11 17:06:00 +01:00
parent c856f2625c
commit f140a94dc6

View File

@ -1350,15 +1350,16 @@ fn box_voxel_collision<T: BaseVol<Vox = Block> + ReadVol>(
read: &PhysicsRead,
ori: &Ori,
) {
let scale = read.scales.get(entity).map_or(1.0, |s| s.0);
// We cap out scale at 10.0 to prevent an enormous amount of lag
let scale = read.scales.get(entity).map_or(1.0, |s| s.0.min(10.0));
//prof_span!("box_voxel_collision");
// Convience function to compute the player aabb
fn player_aabb(pos: Vec3<f32>, radius: f32, z_range: Range<f32>, scale: f32) -> Aabb<f32> {
fn player_aabb(pos: Vec3<f32>, radius: f32, z_range: Range<f32>) -> Aabb<f32> {
Aabb {
min: pos + Vec3::new(-radius, -radius, z_range.start) * scale,
max: pos + Vec3::new(radius, radius, z_range.end) * scale,
min: pos + Vec3::new(-radius, -radius, z_range.start),
max: pos + Vec3::new(radius, radius, z_range.end),
}
}
@ -1381,7 +1382,7 @@ fn box_voxel_collision<T: BaseVol<Vox = Block> + ReadVol>(
z_range: Range<f32>,
scale: f32,
) -> bool {
let player_aabb = player_aabb(pos, radius, z_range, scale);
let player_aabb = player_aabb(pos, radius, z_range);
// Calculate the world space near aabb
let near_aabb = move_aabb(near_aabb, pos);
@ -1407,7 +1408,7 @@ fn box_voxel_collision<T: BaseVol<Vox = Block> + ReadVol>(
#[allow(clippy::trivially_copy_pass_by_ref)]
fn always_hits(_: &Block) -> bool { true }
let (radius, z_min, z_max) = cylinder;
let (radius, z_min, z_max) = (Vec3::from(cylinder) * scale).into_tuple();
// Probe distances
let hdist = radius.ceil() as i32;
@ -1448,7 +1449,7 @@ fn box_voxel_collision<T: BaseVol<Vox = Block> + ReadVol>(
let try_colliding_block = |pos: &Pos| {
//prof_span!("most colliding check");
// Calculate the player's AABB
let player_aabb = player_aabb(pos.0, radius, z_range.clone(), scale);
let player_aabb = player_aabb(pos.0, radius, z_range.clone());
// Determine the block that we are colliding with most
// (based on minimum collision axis)
@ -1498,7 +1499,7 @@ fn box_voxel_collision<T: BaseVol<Vox = Block> + ReadVol>(
.flatten()
{
// Calculate the player's AABB
let player_aabb = player_aabb(pos.0, radius, z_range.clone(), scale);
let player_aabb = player_aabb(pos.0, radius, z_range.clone());
// Find the intrusion vector of the collision
let dir = player_aabb.collision_vector_with_aabb(block_aabb);
@ -1630,7 +1631,7 @@ fn box_voxel_collision<T: BaseVol<Vox = Block> + ReadVol>(
}
// Find liquid immersion and wall collision all in one round of iteration
let player_aabb = player_aabb(pos.0, radius, z_range.clone(), scale);
let player_aabb = player_aabb(pos.0, radius, z_range.clone());
// Calculate the world space near_aabb
let near_aabb = move_aabb(near_aabb, pos.0);