Make e2t hitboxes tighter by checking the floating point coordinates before looking up voxels.

This commit is contained in:
Avi Weinstock 2021-06-15 21:12:13 -04:00
parent 9ed788bb50
commit 5e6363dbcc
2 changed files with 12 additions and 4 deletions

View File

@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed ### Changed
- Entity-entity pushback is no longer applied in forced movement states like rolling and leaping. - Entity-entity pushback is no longer applied in forced movement states like rolling and leaping.
- Updated audio library (rodio 0.13 -> 0.14). - Updated audio library (rodio 0.13 -> 0.14).
- Improve entity-terrain physics performance by reducing the number of voxel lookups.
### Removed ### Removed

View File

@ -1283,11 +1283,18 @@ fn box_voxel_collision<'a, T: BaseVol<Vox = Block> + ReadVol>(
near_iter.filter_map(move |(i, j, k)| { near_iter.filter_map(move |(i, j, k)| {
let block_pos = pos.map(|e| e.floor() as i32) + Vec3::new(i, j, k); let block_pos = pos.map(|e| e.floor() as i32) + Vec3::new(i, j, k);
if let Some(block) = terrain.get(block_pos).ok().copied().filter(hit) { // `near_iter` could be a few blocks too large due to being integer aligned and
// rounding up, so skip points outside of the tighter bounds before looking them
// up in the terrain (which incurs a hashmap cost for volgrids)
let player_aabb = Aabb { let player_aabb = Aabb {
min: pos + Vec3::new(-radius, -radius, z_range.start), min: pos + Vec3::new(-radius, -radius, z_range.start),
max: pos + Vec3::new(radius, radius, z_range.end), max: pos + Vec3::new(radius, radius, z_range.end),
}; };
if !player_aabb.contains_point(block_pos.as_() + Vec3::broadcast(0.5)) {
return None;
}
if let Some(block) = terrain.get(block_pos).ok().copied().filter(hit) {
let block_aabb = Aabb { let block_aabb = Aabb {
min: block_pos.map(|e| e as f32), min: block_pos.map(|e| e as f32),
max: block_pos.map(|e| e as f32) + Vec3::new(1.0, 1.0, height(&block)), max: block_pos.map(|e| e as f32) + Vec3::new(1.0, 1.0, height(&block)),