diff --git a/src/xr_input/trackers.rs b/src/xr_input/trackers.rs index bd61977..bbccc65 100644 --- a/src/xr_input/trackers.rs +++ b/src/xr_input/trackers.rs @@ -1,4 +1,4 @@ -use bevy::log::info; +use bevy::log::{debug, info}; use bevy::prelude::{ Added, BuildChildren, Commands, Component, Entity, Query, Res, Transform, Vec3, With, Without, }; @@ -74,16 +74,19 @@ pub fn update_open_xr_controllers( let left_grip_space = controller.grip_space(Hand::Left); let left_aim_space = controller.aim_space(Hand::Left); let left_postion = left_grip_space.0.pose.position.to_vec3(); - let left_aim_pose = left_controller_query.get_single_mut().unwrap().1; + let left_aim_pose = left_controller_query.get_single_mut(); match left_aim_pose { - Some(mut pose) => { - *pose = AimPose(Transform { - translation: left_aim_space.0.pose.position.to_vec3(), - rotation: left_aim_space.0.pose.orientation.to_quat(), - scale: Vec3::splat(1.0), - }); - } - None => (), + Ok(left_entity) => match left_entity.1 { + Some(mut pose) => { + *pose = AimPose(Transform { + translation: left_aim_space.0.pose.position.to_vec3(), + rotation: left_aim_space.0.pose.orientation.to_quat(), + scale: Vec3::splat(1.0), + }); + } + None => (), + }, + Err(_) => debug!("no left controlelr entity found"), } left_controller_query @@ -99,16 +102,19 @@ pub fn update_open_xr_controllers( let right_aim_space = controller.aim_space(Hand::Right); let right_postion = right_grip_space.0.pose.position.to_vec3(); - let right_aim_pose = right_controller_query.get_single_mut().unwrap().1; + let right_aim_pose = right_controller_query.get_single_mut(); match right_aim_pose { - Some(mut pose) => { - *pose = AimPose(Transform { - translation: right_aim_space.0.pose.position.to_vec3(), - rotation: right_aim_space.0.pose.orientation.to_quat(), - scale: Vec3::splat(1.0), - }); - } - None => (), + Ok(right_entity) => match right_entity.1 { + Some(mut pose) => { + *pose = AimPose(Transform { + translation: right_aim_space.0.pose.position.to_vec3(), + rotation: right_aim_space.0.pose.orientation.to_quat(), + scale: Vec3::splat(1.0), + }); + } + None => (), + }, + Err(_) => debug!("no right controlelr entity found"), } right_controller_query