diff --git a/src/world_interaction/interactions_ui.rs b/src/world_interaction/interactions_ui.rs index d9be4d3e..52b8abf6 100644 --- a/src/world_interaction/interactions_ui.rs +++ b/src/world_interaction/interactions_ui.rs @@ -9,7 +9,7 @@ use crate::{ use crate::{world_interaction::dialog::DialogTarget, GameState}; use anyhow::Context; -use bevy::{prelude::*, window::PrimaryWindow}; +use bevy::{prelude::*, transform::TransformSystem::TransformPropagate, window::PrimaryWindow}; use bevy_egui::{egui, EguiContexts}; use bevy_mod_sysfail::prelude::*; use bevy_xpbd_3d::prelude::*; @@ -24,7 +24,9 @@ pub(crate) fn interactions_ui_plugin(app: &mut App) { .add_systems( Update, ( - update_interaction_opportunities.after(PhysicsSet::Sync), + update_interaction_opportunities + .after(PhysicsSet::Sync) + .after(TransformPropagate), display_interaction_prompt, ) .chain() @@ -43,13 +45,13 @@ pub(crate) struct InteractionOpportunity(pub(crate) Option); #[sysfail(Log)] fn update_interaction_opportunities( mut collisions: EventReader, - player_query: Query<&Transform, With>, + player_query: Query<&GlobalTransform, With>, parents: Query<&Parent>, target_query: Query< - (Entity, &Transform), + (Entity, &GlobalTransform), (With, Without, Without), >, - camera_query: Query<(&IngameCamera, &Transform), Without>, + camera_query: Query<(&IngameCamera, &GlobalTransform), Without>, mut interaction_opportunity: ResMut, ) { interaction_opportunity.0 = None; @@ -79,14 +81,14 @@ fn update_interaction_opportunities( } // Check if we are facing the right way - let player_translation = player_query.get(player).unwrap().translation; + let player_translation = player_query.get(player).unwrap().translation(); let Some((camera, camera_transform)) = camera_query.iter().next() else { continue; }; let is_facing_target = is_facing_target( player_translation, - target_transform.translation, - *camera_transform, + target_transform.translation(), + camera_transform.compute_transform(), camera, ); if is_facing_target { @@ -96,7 +98,7 @@ fn update_interaction_opportunities( } fn get_player_and_target( - player_query: &Query<&Transform, With>, + player_query: &Query<&GlobalTransform, With>, entity_a: Entity, entity_b: Entity, ) -> Option<(Entity, Entity)> {