xr controller update now handles no controller entities

This commit is contained in:
Jay Christy
2023-11-21 13:43:01 -05:00
parent 47a5aa0daa
commit e2b506181a

View File

@@ -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