Skip to content

Add JointGraph and JointCollisionDisabled#799

Merged
Jondolf merged 7 commits into
mainfrom
joint-graph
Aug 2, 2025
Merged

Add JointGraph and JointCollisionDisabled#799
Jondolf merged 7 commits into
mainfrom
joint-graph

Conversation

@Jondolf

@Jondolf Jondolf commented Aug 2, 2025

Copy link
Copy Markdown
Member

Objective

Resolves #259.
Closes #274.

A common requirement when using joints is to disable collisions between the attached bodies, for example a wheel and a car. Collision layers are typically not suitable for this, as you may still want a car to collide with the wheels of other cars. Implementing the desired behavior properly requires custom hooks, which is both inefficient and overly complicated for such a common scenario.

We should have a first-party JointCollisionDisabled component. To implement it efficiently, we also need to maintain an internal JointGraph to track which joints are connected to which bodies. A joint graph is also needed for #578.

Solution

  • Implement a JointGraph that is managed for each joint with a JointGraphPlugin<T: Joint>. To make it work properly, a single entity can now only hold up to one type of joint component. If a joint is added on an entity that already has a joint, the old joint is automatically removed, and a warning is emitted if debug_assertions are enabled.
  • Add a JointCollisionDisabled component for disabling collisions between bodies attached by joints.

Migration Guide

Entities can now only hold up to one type of joint component. If a joint is added on an entity that already has a joint, the old joint is automatically removed, and a warning is emitted if debug_assertions are enabled. A rigid body can still be attached to other bodies by multiple joints, but each joint must be on its own entity.

ContactEdge now also stores the rigid body entities.

@Jondolf Jondolf added this to the 0.4 milestone Aug 2, 2025
@Jondolf Jondolf added C-Feature A new feature, making something new possible A-Dynamics Relates to rigid body dynamics: motion, mass, constraint solving, joints, CCD, and so on M-Migration-Guide A breaking change to Avian's public API that needs to be noted in a migration guide A-Joints Relates to joints constraining the relative positions and orientations of rigid bodies D-Modest A moderate level of difficulty: suitable for simple features or challenging fixes labels Aug 2, 2025
@Jondolf Jondolf marked this pull request as ready for review August 2, 2025 20:34
@Jondolf Jondolf enabled auto-merge (squash) August 2, 2025 20:35
@Jondolf Jondolf merged commit 03ea703 into main Aug 2, 2025
6 checks passed
@Jondolf Jondolf deleted the joint-graph branch August 2, 2025 21:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Dynamics Relates to rigid body dynamics: motion, mass, constraint solving, joints, CCD, and so on A-Joints Relates to joints constraining the relative positions and orientations of rigid bodies C-Feature A new feature, making something new possible D-Modest A moderate level of difficulty: suitable for simple features or challenging fixes M-Migration-Guide A breaking change to Avian's public API that needs to be noted in a migration guide

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Disabling Collision of Bodies Connected with a Joint

1 participant