Sprite AABB does not seem to update with position of the sprites
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 171
Description
## Bevy version
0.14
## What you did

In this picture the two boxes represent the AABBs of the fireball and the small dude in the top-left respectively.
Normal 2D setup with DefaultPlugins and default features. I'm fetching the AABBs gizmos like so:
```rust
fn check_for_projectile_collisions(
projectile_query: Query<(&Aabb, &Target), With>,
unit_query: Query<&Aabb, With>>,
mut gizmos: Gizmos,
) {
for (projectile_aabb, target) in projectile_query.iter() {
// TODO: handle case where no specific target is set
let target_entity = target.entity.unwrap();
let Ok(target_aabb) = unit_query.get(target_entity) else {
// The unit may have been despawned.
continue;
};
let projectile_bounding_box = Aabb2d::new(
projectile_aabb.center.truncate(),
projectile_aabb.half_extents.truncate(),
);
let target_bounding_box = Aabb2d::new(
target_aabb.center.truncate(),
target_aabb.half_extents.truncate(),
);
let gizmo_color = if projectile_bounding_box.intersects(&target_bounding_box) {
Color::from(LinearRgba::RED)
} else {
Color::WHITE
};
gizmos.rect_2d(
projectile_aabb.center.truncate(),
Rot2::radians(0.),
projectile_aabb.half_extents.truncate(),
gizmo_color,
);
gizmos.rect_2d(
target_aabb.center.truncate(),
Rot2::radians(0.),
target_aabb.half_extents.truncate(),
gizmo_color,
);
}
}
```
## What went wrong
The position of the Aabb doesn't move as the sprites move. This can be quickly double-checked with bevy_inspector_egui: the `center` of all the `Aabb`s in my scene is (0,0,0).
## Additional information
This is related to #11892 as its a bug in the same area of code, but I don't think it's the same root cause.
As a workaround, you can fetch the correct center using `GlobalTransform`.
```rust
let projectile_center = projectile_global_transform.translation().truncate();
```
Contributor guide
Research direction
Start with the DefaultPlugins 2D setup and inspect how Aabb centers are populated or updated relative to GlobalTransform. Reproduce the issue by moving sprites and comparing Aabb.center with GlobalTransform.translation(), then verify that the AABB follows the sprite position while preserving the reported collision behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- game-dev
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100