better targeting handling
This commit is contained in:
parent
974de97ded
commit
2f65c652c8
|
@ -7,6 +7,7 @@ actor 0 0 0 jupiter
|
||||||
rotationx -0.50
|
rotationx -0.50
|
||||||
rotationz -0.28
|
rotationz -0.28
|
||||||
angularmomentum 30 30 30
|
angularmomentum 30 30 30
|
||||||
|
clickable no
|
||||||
|
|
||||||
actor 0 593051 0 suit
|
actor 0 593051 0 suit
|
||||||
relativeto jupiter
|
relativeto jupiter
|
||||||
|
|
18
src/hud.rs
18
src/hud.rs
|
@ -598,17 +598,20 @@ fn handle_input(
|
||||||
ew_togglemusic.send(audio::ToggleMusicEvent());
|
ew_togglemusic.send(audio::ToggleMusicEvent());
|
||||||
}
|
}
|
||||||
if mouse_input.just_pressed(settings.key_selectobject) {
|
if mouse_input.just_pressed(settings.key_selectobject) {
|
||||||
if q_target.is_empty() {
|
|
||||||
if let Ok(camtrans) = q_camera.get_single() {
|
if let Ok(camtrans) = q_camera.get_single() {
|
||||||
let objects: Vec<(Entity, &Transform)> = q_objects
|
let objects: Vec<(Entity, &Transform)> = q_objects.iter().collect();
|
||||||
.iter()
|
if let (Some(new_target), _dist) = camera::find_closest_target::<Entity>(objects, camtrans) {
|
||||||
.map(|(entity, transform)| (entity, transform))
|
if let Ok(old_target) = q_target.get_single() {
|
||||||
.collect();
|
if old_target != new_target {
|
||||||
if let (Some(entity), _dist) = camera::find_closest_target::<Entity>(objects, camtrans) {
|
commands.entity(old_target).remove::<IsTargeted>();
|
||||||
commands.entity(entity).insert(IsTargeted);
|
commands.entity(new_target).insert(IsTargeted);
|
||||||
ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::Click));
|
ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::Click));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
commands.entity(new_target).insert(IsTargeted);
|
||||||
|
ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::Click));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
for entity in &q_target {
|
for entity in &q_target {
|
||||||
|
@ -617,4 +620,5 @@ fn handle_input(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue