Skip to content

Replace collision code in breakout example with code based Aabb2d::intersects #11479

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rparrett opened this issue Jan 22, 2024 · 3 comments · Fixed by #11500
Closed

Replace collision code in breakout example with code based Aabb2d::intersects #11479

rparrett opened this issue Jan 22, 2024 · 3 comments · Fixed by #11500
Labels
A-Physics Collisions, kinematics, forces and more C-Examples An addition or correction to our examples C-Feature A new feature, making something new possible

Comments

@rparrett
Copy link
Contributor

rparrett commented Jan 22, 2024

What problem does this solve or what need does it fill?

After #11439, it seems like it might be possible to nuke the breakout example's custom collision code.

The breakout example makes use of bevy::sprite::collide_aabb::collide which exists in Bevy solely to make this particular example work.

The current collision code also assumes that the ball is a rectangle, which is no longer true!

What solution would you like?

Replace the code in breakout with code based on the new bounding volume intersection stuff introduced in #11439 and remove bevy::sprite::collide_aabb::collide from Bevy.

breakout is relying on collide_aabb::collide determining "which side of the thing was collided with," so this is slightly more involved than it sounds on the surface.

What alternative(s) have you considered?

Maybe I've misjudged and it's not time for this yet.

@rparrett rparrett added C-Feature A new feature, making something new possible S-Needs-Triage This issue needs to be labelled C-Examples An addition or correction to our examples A-Physics Collisions, kinematics, forces and more and removed S-Needs-Triage This issue needs to be labelled labels Jan 22, 2024
@rparrett
Copy link
Contributor Author

rparrett commented Jan 22, 2024

Pinging @Jondolf for an opinion / maybe some guidance for someone wanting to do this.

@alice-i-cecile alice-i-cecile added D-Trivial Nice and easy! A great choice to get started with Bevy and removed D-Trivial Nice and easy! A great choice to get started with Bevy labels Jan 22, 2024
@alice-i-cecile
Copy link
Member

alice-i-cecile commented Jan 22, 2024

IMO we should definitely remove the aabb methods from bevy_sprite as part of the same PR. It's always felt like an out-of-place hack, and this would be a good demonstration about how it's no longer needed.

@Jondolf
Copy link
Contributor

Jondolf commented Jan 22, 2024

Yes, I agree we should remove the AABB and collision stuff from bevy_sprite and move collide to the breakout example.

Aabb2d can be used to replace CollisionBox, and intersects can be used for the initial intersection check, but the side-detection logic will still need to be done manually

github-merge-queue bot pushed a commit that referenced this issue Jan 29, 2024
# Objective

Fixes #11479

## Solution

- Remove `collide_aabb.rs`
- Re-implement the example-specific collision code in the example,
taking advantage of the new `IntersectsVolume` trait.

## Changelog

- Removed `sprite::collide_aabb::collide` and
`sprite::collide_aabb::Collision`.

## Migration Guide

`sprite::collide_aabb::collide` and `sprite::collide_aabb::Collision`
were removed.

```rust
// Before
let collision = bevy::sprite::collide_aabb::collide(a_pos, a_size, b_pos, b_size);
if collision.is_some() {
    // ...
}

// After
let collision = Aabb2d::new(a_pos.truncate(), a_size / 2.)
    .intersects(&Aabb2d::new(b_pos.truncate(), b_size / 2.));
if collision {
    // ...
}
```

If you were making use `collide_aabb::Collision`, see the new
`collide_with_side` function in the [`breakout`
example](https://bevyengine.org/examples/Games/breakout/).

## Discussion

As discussed in the linked issue, maybe we want to wait on `bevy_sprite`
generally making use of `Aabb2b` so users don't need to construct it
manually. But since they **do** need to construct the bounding circle
for the ball manually, this doesn't seem like a big deal to me.

---------

Co-authored-by: IQuick 143 <[email protected]>
tjamaan pushed a commit to tjamaan/bevy that referenced this issue Feb 6, 2024
)

# Objective

Fixes bevyengine#11479

## Solution

- Remove `collide_aabb.rs`
- Re-implement the example-specific collision code in the example,
taking advantage of the new `IntersectsVolume` trait.

## Changelog

- Removed `sprite::collide_aabb::collide` and
`sprite::collide_aabb::Collision`.

## Migration Guide

`sprite::collide_aabb::collide` and `sprite::collide_aabb::Collision`
were removed.

```rust
// Before
let collision = bevy::sprite::collide_aabb::collide(a_pos, a_size, b_pos, b_size);
if collision.is_some() {
    // ...
}

// After
let collision = Aabb2d::new(a_pos.truncate(), a_size / 2.)
    .intersects(&Aabb2d::new(b_pos.truncate(), b_size / 2.));
if collision {
    // ...
}
```

If you were making use `collide_aabb::Collision`, see the new
`collide_with_side` function in the [`breakout`
example](https://bevyengine.org/examples/Games/breakout/).

## Discussion

As discussed in the linked issue, maybe we want to wait on `bevy_sprite`
generally making use of `Aabb2b` so users don't need to construct it
manually. But since they **do** need to construct the bounding circle
for the ball manually, this doesn't seem like a big deal to me.

---------

Co-authored-by: IQuick 143 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Physics Collisions, kinematics, forces and more C-Examples An addition or correction to our examples C-Feature A new feature, making something new possible
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants