Skip to content
New issue

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

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

Already on GitHub? # to your account

Add convenience methods for determining if collisions are starting or stopping #529

Merged
merged 1 commit into from
Oct 7, 2024

Conversation

ndarilek
Copy link
Contributor

@ndarilek ndarilek commented Oct 6, 2024

Objective

It can be tricky to match and handle all of an entity's collision states in a single event loop. I routinely find myself writing code like this:

    for Collision(contacts)in events.read() {
        let started = contacts.during_current_frame && !contacts.during_previous_frame;
        let stopped = !contacts.during_current_frame && contacts.during_previous_frame;
        if started {
        } else if stopped {
        }

Solution

Add Contacts::collision_started and Contacts::collision_stopped to more conveniently check these conditions.

Changelog

Added

  • Added Contacts::collision_started and Contacts::collision_stopped for more conveniently checking if a collision just started or stopped.

@Jondolf Jondolf added A-Collision Relates to the broad phase, narrow phase, colliders, or other collision functionality C-Usability A quality-of-life improvement that makes Avian easier to use labels Oct 7, 2024
@Jondolf Jondolf enabled auto-merge (squash) October 7, 2024 00:16
@Jondolf Jondolf merged commit 4ea5373 into Jondolf:main Oct 7, 2024
4 checks passed
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-Collision Relates to the broad phase, narrow phase, colliders, or other collision functionality C-Usability A quality-of-life improvement that makes Avian easier to use
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants