Skip to content
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

Use IntersectsVolume for breakout example collisions #11500

Merged
merged 5 commits into from
Jan 29, 2024

Conversation

rparrett
Copy link
Contributor

@rparrett rparrett commented Jan 23, 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.

// 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.

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.

@Jondolf Jondolf added C-Examples An addition or correction to our examples C-Code-Quality A section of code that is hard to understand or change A-Physics Collisions, kinematics, forces and more labels Jan 23, 2024
@rparrett rparrett changed the title Use Aabb2d::intersects for breakout example collisions Use Aabb2d::intersects for breakout example collisions Jan 24, 2024
@rparrett rparrett changed the title Use Aabb2d::intersects for breakout example collisions Use IntersectsVolume for breakout example collisions Jan 24, 2024
examples/games/breakout.rs Outdated Show resolved Hide resolved
examples/games/breakout.rs Outdated Show resolved Hide resolved
rparrett and others added 2 commits January 24, 2024 07:55
Co-authored-by: IQuick 143 <IQuick143cz@gmail.com>
Co-authored-by: IQuick 143 <IQuick143cz@gmail.com>
@rparrett rparrett marked this pull request as ready for review January 24, 2024 15:14
Copy link
Contributor

@Jondolf Jondolf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty good to me! A couple of simple comments on the collision function could be nice especially since this is an example, but it's quite understandable either way so it's non-blocking

@rparrett rparrett added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Jan 25, 2024
@alice-i-cecile alice-i-cecile added the C-Breaking-Change A breaking change to Bevy's public API that needs to be noted in a migration guide label Jan 28, 2024
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Jan 29, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jan 29, 2024
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Jan 29, 2024
Merged via the queue into bevyengine:main with commit 1bc293f Jan 29, 2024
24 checks passed
@Jondolf Jondolf mentioned this pull request Feb 4, 2024
46 tasks
tjamaan pushed a commit to tjamaan/bevy that referenced this pull request 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 <IQuick143cz@gmail.com>
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-Breaking-Change A breaking change to Bevy's public API that needs to be noted in a migration guide C-Code-Quality A section of code that is hard to understand or change C-Examples An addition or correction to our examples S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replace collision code in breakout example with code based Aabb2d::intersects
4 participants