|
1 | 1 | use crate::movement::character_controller::FloatHeight;
|
2 | 2 | use bevy::prelude::*;
|
| 3 | +use bevy::render::view::NoFrustumCulling; |
3 | 4 | use bevy_tnua::controller::TnuaController;
|
4 | 5 | use bevy_xpbd_3d::prelude::*;
|
5 | 6 |
|
6 | 7 | /// Shift models down because XPBD will make controllers float,
|
7 | 8 | /// but our models definitely should not be floating!
|
8 | 9 | pub(crate) fn offset_models_to_controller(
|
9 |
| - controllers: Query< |
10 |
| - (&Transform, &FloatHeight, &Children), |
11 |
| - (Added<TnuaController>, With<Collider>), |
12 |
| - >, |
| 10 | + mut commands: Commands, |
| 11 | + controllers: Query<(Entity, &Transform, &FloatHeight), (Added<TnuaController>, With<Collider>)>, |
13 | 12 | mut transforms: Query<&mut Transform, Without<Collider>>,
|
| 13 | + children_q: Query<&Children>, |
14 | 14 | ) {
|
15 |
| - for (transform, float_height, children) in controllers.iter() { |
| 15 | + for (entity, transform, float_height) in controllers.iter() { |
16 | 16 | let offset = (float_height.0 / transform.scale.y) * 2.;
|
| 17 | + let children = children_q.get(entity).unwrap(); |
17 | 18 | for child in children.iter() {
|
18 | 19 | if let Ok(mut model_transform) = transforms.get_mut(*child) {
|
19 | 20 | model_transform.translation.y -= offset;
|
20 | 21 | }
|
21 | 22 | }
|
| 23 | + |
| 24 | + // Frustum culling is erroneous for animated models because the AABB is not updated. |
| 25 | + commands.entity(entity).insert(NoFrustumCulling); |
| 26 | + for entity in children_q.iter_descendants(entity) { |
| 27 | + commands.entity(entity).insert(NoFrustumCulling); |
| 28 | + } |
22 | 29 | }
|
23 | 30 | }
|
0 commit comments