Use correct scaling for volume entity collisions

This commit is contained in:
Maxicarlos08 2024-01-01 13:22:10 +01:00
parent 004be6395f
commit 551d783cac
No known key found for this signature in database
2 changed files with 21 additions and 48 deletions

View File

@ -562,10 +562,11 @@ impl<'a> PhysicsData<'a> {
let radius_cutoff = 64;
let mut spatial_grid = SpatialGrid::new(lg2_cell_size, lg2_large_cell_size, radius_cutoff);
// TODO: give voxel colliders their own component type
for (entity, pos, collider, ori) in (
for (entity, pos, collider, scale, ori) in (
&read.entities,
&write.positions,
&read.colliders,
read.scales.maybe(),
&write.orientations,
)
.join()
@ -573,7 +574,7 @@ impl<'a> PhysicsData<'a> {
let vol = collider.get_vol(&voxel_colliders_manifest);
if let Some(vol) = vol {
let sphere = voxel_collider_bounding_sphere(vol, pos, ori);
let sphere = voxel_collider_bounding_sphere(vol, pos, ori, scale);
let radius = sphere.radius.ceil() as u32;
let pos_2d = sphere.center.xy().map(|e| e as i32);
const POS_TRUNCATION_ERROR: u32 = 1;
@ -1084,15 +1085,17 @@ impl<'a> PhysicsData<'a> {
voxel_collider_spatial_grid
.in_circle_aabr(query_center, query_radius)
.filter_map(|entity| {
positions
.get(entity)
.and_then(|l| velocities.get(entity).map(|r| (l, r)))
.and_then(|l| previous_phys_cache.get(entity).map(|r| (l, r)))
.and_then(|l| read.colliders.get(entity).map(|r| (l, r)))
.and_then(|l| orientations.get(entity).map(|r| (l, r)))
.map(|((((pos, vel), previous_cache), collider), ori)| {
(entity, pos, vel, previous_cache, collider, ori)
})
positions.get(entity).and_then(|pos| {
Some((
entity,
pos,
velocities.get(entity)?,
previous_phys_cache.get(entity)?,
read.colliders.get(entity)?,
read.scales.get(entity),
orientations.get(entity)?,
))
})
})
.for_each(
|(
@ -1101,6 +1104,7 @@ impl<'a> PhysicsData<'a> {
vel_other,
previous_cache_other,
collider_other,
scale_other,
ori_other,
)| {
if entity == entity_other {
@ -1126,6 +1130,7 @@ impl<'a> PhysicsData<'a> {
voxel_collider,
pos_other,
ori_other,
scale_other,
);
// Early check
if voxel_sphere.center.distance_squared(path_sphere.center)
@ -1942,6 +1947,7 @@ fn voxel_collider_bounding_sphere(
voxel_collider: &VoxelCollider,
pos: &Pos,
ori: &Ori,
scale: Option<&Scale>,
) -> Sphere<f32, f32> {
let origin_offset = voxel_collider.translation;
use common::vol::SizedVol;
@ -1964,7 +1970,7 @@ fn voxel_collider_bounding_sphere(
Sphere {
center: wpos_center,
radius,
radius: radius * scale.map_or(1.0, |s| s.0),
}
}

View File

@ -1941,44 +1941,11 @@ fn handle_spawn_campfire(
_action: &ServerChatCommand,
) -> CmdResult<()> {
let pos = position(server, target, "target")?;
let time = server.state.get_time();
server
.state
.create_object(pos, comp::object::Body::CampfireLit)
.with(LightEmitter {
col: Rgb::new(1.0, 0.65, 0.2),
strength: 2.0,
flicker: 1.0,
animated: true,
})
.with(WaypointArea::default())
.with(comp::Auras::new(vec![
Aura::new(
AuraKind::Buff {
kind: BuffKind::CampfireHeal,
data: BuffData::new(0.02, Some(Secs(1.0))),
category: BuffCategory::Natural,
source: BuffSource::World,
},
5.0,
None,
AuraTarget::All,
Time(time),
),
Aura::new(
AuraKind::Buff {
kind: BuffKind::Burning,
data: BuffData::new(2.0, Some(Secs(10.0))),
category: BuffCategory::Natural,
source: BuffSource::World,
},
0.7,
None,
AuraTarget::All,
Time(time),
),
]))
.build();
.ecs()
.read_resource::<EventBus<ServerEvent>>()
.emit_now(ServerEvent::CreateWaypoint(pos.0));
server.notify_client(
client,