better solution for thruster particle crash

This commit is contained in:
yuni 2024-10-05 04:26:44 +02:00
parent b5105ff4c5
commit 4d19495ab5

View file

@ -696,7 +696,16 @@ fn handle_wants_maxvelocity(
} }
fn handle_wants_lookat( fn handle_wants_lookat(
mut query: Query<(&Position, &mut Rotation, &WantsToLookAt), Without<Camera>>, mut query: Query<
(
&Position,
&mut Rotation,
&Transform,
&WantsToLookAt,
Option<&visual::IsEffect>,
),
Without<Camera>,
>,
q_playercam: Query<&Position, With<PlayerCamera>>, q_playercam: Query<&Position, With<PlayerCamera>>,
q_cam: Query<&Transform, With<Camera>>, q_cam: Query<&Transform, With<Camera>>,
id2pos: Res<game::Id2Pos>, id2pos: Res<game::Id2Pos>,
@ -713,7 +722,7 @@ fn handle_wants_lookat(
}; };
// TODO: use ExternalTorque rather than hard-resetting the rotation // TODO: use ExternalTorque rather than hard-resetting the rotation
for (pos, mut rot, target_id) in &mut query { for (pos, mut rot, trans, target_id, is_effect) in &mut query {
let target_pos: DVec3 = if target_id.0 == cmd::ID_SPECIAL_PLAYERCAM { let target_pos: DVec3 = if target_id.0 == cmd::ID_SPECIAL_PLAYERCAM {
cam_pos cam_pos
} else if let Some(target_pos) = id2pos.0.get(&target_id.0) { } else if let Some(target_pos) = id2pos.0.get(&target_id.0) {
@ -721,12 +730,16 @@ fn handle_wants_lookat(
} else { } else {
continue; continue;
}; };
//let up = if trans.translation.length_squared() > 1e-6 { let up = if is_effect.is_some() {
// trans.up() // trans.up() sometimes crashes with thruster particle effects
//} else { Dir3::Y
// Dir3::Y } else {
//}; if trans.translation.length_squared() > 1e-6 {
let up = Dir3::Y; // TODO: the above code seems to be buggy, this is a workaround trans.up()
} else {
Dir3::Y
}
};
rot.0 = look_at_quat(**pos, target_pos, up.as_dvec3()); rot.0 = look_at_quat(**pos, target_pos, up.as_dvec3());
} }
} }