Skip to content

AnyCollider context#527

Closed
oxkitsune wants to merge 11 commits into
avianphysics:mainfrom
oxkitsune:gijs/collision-context
Closed

AnyCollider context#527
oxkitsune wants to merge 11 commits into
avianphysics:mainfrom
oxkitsune:gijs/collision-context

Conversation

@oxkitsune

Copy link
Copy Markdown
Contributor

Objective

Provide a way for the methods in AnyCollider to obtain extra context from the ecs/entity it is attached to.

Solution

  • Add a Context GAT to the AnyCollider trait
  • Optionally query for this context in the broad/narrow phase
  • Pass the Option<Context> to the AnyCollider methods when called

Changelog

  • Changed: AnyCollider requires a Context GAT, to provide additional context from the ecs.

@oxkitsune

Copy link
Copy Markdown
Contributor Author

This is a draft, as I'm looking for comments/feedback on the implementation.
Perhaps there is a better approach, but I'm not super familiar with avian's internals. Or this not something avian is looking for. either way, I'm curious to hear what you think 😄

Jondolf added a commit that referenced this pull request Mar 20, 2025
# Objective

- Updated version of #527 with some changes suggested by Jondolf

## Solution

- Reapply the changes from the previous PR
- Add a `SimpleCollider` trait that works for colliders with no context to shorten function signatures

## Changelog

- Custom colliders can now specify a SystemParam via `AnyCollider::Context`
- The context is passed to all `AnyCollider` methods, allowing data from the `World` to be fetched
- AnyCollider functions have been suffixed with `_with_collider`
- A new `SimpleCollider` trait has been added to retain the simplified methods for colliders that don't need context

## Migration Guide

- Custom colliders now need to specify a `Context` `SystemParam`, if this is unnecessary `()` should be used
- When trying to use methods from `AnyCollider` on an implementation with `()` context, `SimpleCollider` should be used instead
- Methods on `AnyCollider` have been suffixed with `_with_context`

---------

Co-authored-by: Gijs de Jong <14833076+oxkitsune@users.noreply.github.com>
Co-authored-by: aecsocket <aecsocket@tutanota.com>
Co-authored-by: Joona Aalto <jondolf.dev@gmail.com>
@Jondolf

Jondolf commented Mar 20, 2025

Copy link
Copy Markdown
Member

Adopted in #665, which was just merged. Closing :)

@Jondolf Jondolf closed this Mar 20, 2025
Jondolf added a commit that referenced this pull request Mar 21, 2025
# Objective

#527 used a read-only `UnsafeWorldCell` for the initialization of `ColliderAabb` in an `on_add` hook for `Collider`. However, it uses methods that provide mutable access, which is unsafe and panics with debug assertions.

## Solution

Remove the whole AABB initialization logic and use of `unsafe`. Having it didn't make sense since the initial positions are likely wrong anyway.

`ColliderAabb` is now explicitly specified to be `ColliderAabb::INVALID` until the first physics update.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants