Compare commits
No commits in common. "1f3aa8eaa068ca7e8f01b1b55e798c6d1aee4f50" and "1020f818b95eae80353c64b3e0debb3c81d8744a" have entirely different histories.
1f3aa8eaa0
...
1020f818b9
|
@ -270,7 +270,7 @@ fn add_speed(mut commands: Commands, query: Query<Entity, (Added<Speed>, Without
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn limit_speed(mut query: Query<(&mut Speed, &MaxSpeed)>) {
|
fn limit_speed(mut query: Query<(&mut Speed, &MaxSpeed)>) {
|
||||||
for (mut speed, max_speed) in &mut query {
|
for (mut speed, max_speed) in &mut query {
|
||||||
if **speed > **max_speed {
|
if **speed > **max_speed {
|
||||||
**speed = **max_speed;
|
**speed = **max_speed;
|
||||||
|
@ -391,11 +391,7 @@ where
|
||||||
.add_system_to_stage(CoreStage::PostUpdate, log_area_descriptions::<S, A>);
|
.add_system_to_stage(CoreStage::PostUpdate, log_area_descriptions::<S, A>);
|
||||||
const MOVEMENT_CONTROLS: &str = "MOVEMENT_CONTROLS";
|
const MOVEMENT_CONTROLS: &str = "MOVEMENT_CONTROLS";
|
||||||
if config.movement_control_states.is_empty() {
|
if config.movement_control_states.is_empty() {
|
||||||
app.add_system(
|
app.add_system(movement_controls::<S>.label(MOVEMENT_CONTROLS))
|
||||||
movement_controls::<S>
|
|
||||||
.label(MOVEMENT_CONTROLS)
|
|
||||||
.after(limit_speed),
|
|
||||||
)
|
|
||||||
.add_system(snap.chain(error_handler).before(MOVEMENT_CONTROLS));
|
.add_system(snap.chain(error_handler).before(MOVEMENT_CONTROLS));
|
||||||
} else {
|
} else {
|
||||||
let states = config.movement_control_states;
|
let states = config.movement_control_states;
|
||||||
|
|
|
@ -8,16 +8,32 @@ use crate::{commands::RunIfExistsExt, core::GlobalTransformExt};
|
||||||
pub struct Volumetric;
|
pub struct Volumetric;
|
||||||
|
|
||||||
fn update(
|
fn update(
|
||||||
|
mut commands: Commands,
|
||||||
listener: Query<(&Collider, &GlobalTransform), With<Listener>>,
|
listener: Query<(&Collider, &GlobalTransform), With<Listener>>,
|
||||||
mut sounds: Query<(&Sound, &Parent, &mut Transform), With<Volumetric>>,
|
mut sounds: Query<
|
||||||
colliders: Query<(&Collider, &GlobalTransform)>,
|
(
|
||||||
|
Entity,
|
||||||
|
Option<&Collider>,
|
||||||
|
Option<&Parent>,
|
||||||
|
&mut Transform,
|
||||||
|
&GlobalTransform,
|
||||||
|
),
|
||||||
|
With<Volumetric>,
|
||||||
|
>,
|
||||||
|
colliders: Query<&Collider>,
|
||||||
) {
|
) {
|
||||||
if let Ok((listener_collider, listener_global_transform)) = listener.get_single() {
|
if let Ok((listener_collider, listener_global_transform)) = listener.get_single() {
|
||||||
for (sound, parent, mut sound_transform) in &mut sounds {
|
for (sound_entity, sound_collider, parent, mut sound_transform, sound_global_transform) in
|
||||||
if sound.paused {
|
&mut sounds
|
||||||
continue;
|
{
|
||||||
}
|
let sound_collider = if sound_collider.is_some() {
|
||||||
if let Ok((sound_collider, sound_global_transform)) = colliders.get(**parent) {
|
sound_collider
|
||||||
|
} else if let Some(parent) = parent {
|
||||||
|
colliders.get(**parent).ok()
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
if let Some(sound_collider) = sound_collider {
|
||||||
let closest = listener_global_transform.closest_points(
|
let closest = listener_global_transform.closest_points(
|
||||||
listener_collider,
|
listener_collider,
|
||||||
sound_global_transform,
|
sound_global_transform,
|
||||||
|
@ -25,9 +41,18 @@ fn update(
|
||||||
);
|
);
|
||||||
if let ClosestPoints::WithinMargin(_p1, p2) = closest {
|
if let ClosestPoints::WithinMargin(_p1, p2) = closest {
|
||||||
let p2 = Vec3::new(p2.x, p2.y, 0.);
|
let p2 = Vec3::new(p2.x, p2.y, 0.);
|
||||||
sound_transform.translation.x = p2.x - sound_global_transform.translation().x;
|
if p2.distance(sound_global_transform.translation()) >= 1. {
|
||||||
sound_transform.translation.y = p2.y - sound_global_transform.translation().y;
|
sound_transform.translation.x =
|
||||||
|
p2.x - sound_global_transform.translation().x;
|
||||||
|
sound_transform.translation.y =
|
||||||
|
p2.y - sound_global_transform.translation().y;
|
||||||
|
}
|
||||||
} else if closest == ClosestPoints::Intersecting {
|
} else if closest == ClosestPoints::Intersecting {
|
||||||
|
if sound_global_transform
|
||||||
|
.translation()
|
||||||
|
.distance(listener_global_transform.translation())
|
||||||
|
>= 1.
|
||||||
|
{
|
||||||
sound_transform.translation.x = listener_global_transform.translation().x
|
sound_transform.translation.x = listener_global_transform.translation().x
|
||||||
- sound_global_transform.translation().x;
|
- sound_global_transform.translation().x;
|
||||||
sound_transform.translation.y = listener_global_transform.translation().y
|
sound_transform.translation.y = listener_global_transform.translation().y
|
||||||
|
@ -37,6 +62,7 @@ fn update(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn removed(mut commands: Commands, removed: RemovedComponents<Volumetric>) {
|
fn removed(mut commands: Commands, removed: RemovedComponents<Volumetric>) {
|
||||||
for entity in removed.iter() {
|
for entity in removed.iter() {
|
||||||
|
|
|
@ -85,7 +85,7 @@ impl Viewshed {
|
||||||
);
|
);
|
||||||
let mut context: Context<u8> = Context::default();
|
let mut context: Context<u8> = Context::default();
|
||||||
let vision_distance = vision_distance::Circle::new(self.range);
|
let vision_distance = vision_distance::Circle::new(self.range);
|
||||||
let shape = Collider::cuboid(0.49, 0.49);
|
let shape = Collider::cuboid(0.5 - f32::EPSILON, 0.5 - f32::EPSILON);
|
||||||
let mut new_visible_entities = HashSet::new();
|
let mut new_visible_entities = HashSet::new();
|
||||||
let size = (
|
let size = (
|
||||||
(start.translation().x.abs() + self.range as f32) as u32,
|
(start.translation().x.abs() + self.range as f32) as u32,
|
||||||
|
@ -96,7 +96,7 @@ impl Viewshed {
|
||||||
RefCell::new(Box::new(|coord: Coord| {
|
RefCell::new(Box::new(|coord: Coord| {
|
||||||
let shape_pos = Vec2::new(coord.x as f32 + 0.5, coord.y as f32 + 0.5);
|
let shape_pos = Vec2::new(coord.x as f32 + 0.5, coord.y as f32 + 0.5);
|
||||||
// println!("Checking {:?}", shape_pos);
|
// println!("Checking {:?}", shape_pos);
|
||||||
if start.distance(&shape_pos) > self.range as f32 {
|
if start.distance(&shape_pos) > self.range as f32 + 1. {
|
||||||
// println!("Out of range");
|
// println!("Out of range");
|
||||||
return u8::MAX;
|
return u8::MAX;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user