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 radius_cutoff = 64;
let mut spatial_grid = SpatialGrid::new(lg2_cell_size, lg2_large_cell_size, radius_cutoff); let mut spatial_grid = SpatialGrid::new(lg2_cell_size, lg2_large_cell_size, radius_cutoff);
// TODO: give voxel colliders their own component type // TODO: give voxel colliders their own component type
for (entity, pos, collider, ori) in ( for (entity, pos, collider, scale, ori) in (
&read.entities, &read.entities,
&write.positions, &write.positions,
&read.colliders, &read.colliders,
read.scales.maybe(),
&write.orientations, &write.orientations,
) )
.join() .join()
@ -573,7 +574,7 @@ impl<'a> PhysicsData<'a> {
let vol = collider.get_vol(&voxel_colliders_manifest); let vol = collider.get_vol(&voxel_colliders_manifest);
if let Some(vol) = vol { 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 radius = sphere.radius.ceil() as u32;
let pos_2d = sphere.center.xy().map(|e| e as i32); let pos_2d = sphere.center.xy().map(|e| e as i32);
const POS_TRUNCATION_ERROR: u32 = 1; const POS_TRUNCATION_ERROR: u32 = 1;
@ -1084,14 +1085,16 @@ impl<'a> PhysicsData<'a> {
voxel_collider_spatial_grid voxel_collider_spatial_grid
.in_circle_aabr(query_center, query_radius) .in_circle_aabr(query_center, query_radius)
.filter_map(|entity| { .filter_map(|entity| {
positions positions.get(entity).and_then(|pos| {
.get(entity) Some((
.and_then(|l| velocities.get(entity).map(|r| (l, r))) entity,
.and_then(|l| previous_phys_cache.get(entity).map(|r| (l, r))) pos,
.and_then(|l| read.colliders.get(entity).map(|r| (l, r))) velocities.get(entity)?,
.and_then(|l| orientations.get(entity).map(|r| (l, r))) previous_phys_cache.get(entity)?,
.map(|((((pos, vel), previous_cache), collider), ori)| { read.colliders.get(entity)?,
(entity, pos, vel, previous_cache, collider, ori) read.scales.get(entity),
orientations.get(entity)?,
))
}) })
}) })
.for_each( .for_each(
@ -1101,6 +1104,7 @@ impl<'a> PhysicsData<'a> {
vel_other, vel_other,
previous_cache_other, previous_cache_other,
collider_other, collider_other,
scale_other,
ori_other, ori_other,
)| { )| {
if entity == entity_other { if entity == entity_other {
@ -1126,6 +1130,7 @@ impl<'a> PhysicsData<'a> {
voxel_collider, voxel_collider,
pos_other, pos_other,
ori_other, ori_other,
scale_other,
); );
// Early check // Early check
if voxel_sphere.center.distance_squared(path_sphere.center) if voxel_sphere.center.distance_squared(path_sphere.center)
@ -1942,6 +1947,7 @@ fn voxel_collider_bounding_sphere(
voxel_collider: &VoxelCollider, voxel_collider: &VoxelCollider,
pos: &Pos, pos: &Pos,
ori: &Ori, ori: &Ori,
scale: Option<&Scale>,
) -> Sphere<f32, f32> { ) -> Sphere<f32, f32> {
let origin_offset = voxel_collider.translation; let origin_offset = voxel_collider.translation;
use common::vol::SizedVol; use common::vol::SizedVol;
@ -1964,7 +1970,7 @@ fn voxel_collider_bounding_sphere(
Sphere { Sphere {
center: wpos_center, 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, _action: &ServerChatCommand,
) -> CmdResult<()> { ) -> CmdResult<()> {
let pos = position(server, target, "target")?; let pos = position(server, target, "target")?;
let time = server.state.get_time();
server server
.state .state
.create_object(pos, comp::object::Body::CampfireLit) .ecs()
.with(LightEmitter { .read_resource::<EventBus<ServerEvent>>()
col: Rgb::new(1.0, 0.65, 0.2), .emit_now(ServerEvent::CreateWaypoint(pos.0));
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();
server.notify_client( server.notify_client(
client, client,