Repository navigation
Add collision enter and exit events, and collision layers and masks - #4
Merged
Merged
Conversation
Batch 3 of ROADMAP.md. - CollisionListener gets collisionEnter (the first step two bodies touch) and collisionExit (the first step they don't, or when one is removed from the world), alongside the existing per-contact collision. - All listener calls are now queued during the step and sent at its end, in body-id-pair order. A listener can kill entities safely: before, a body killed in a callback was still narrow-phased and solved for the rest of the step. A pair only counts as touching once its enter is sent, so a body removed mid-dispatch only sends exits for enters that were delivered. - Rigidbody collision layer and mask. Two bodies collide only if each one's layer is in the other's mask. Checked in the broad phase, serialised as optional fields, and editable in the inspector as hex. Raycasts take an optional mask. World::isTouching reports the current contact state. - Bodies moved by game code (setPosition, the tp command) update their grid cells at the start of each step. Before, the broad phase saw them in their old cells for one step, so they missed collisions in their new place. - Entity::kill and ~Entity mark the entity dead before ending components, and Scene::~Scene clears contacts first, so dying entities and scene teardown get no exit events. - The demo's impact flash uses collisionEnter and last frame's speed, since velocities read in callbacks are now post-solve. Tests: new unit test test_collision_events for enter, contact and exit events, exits on removal, killing bodies from listeners, layers and masks, raycast masks, and serialisation. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015cNAkNqoDWA5gFReD1AsqV
RohanFredriksson
changed the base branch from
claude/gameplay-api-batch2
to
master
October 16, 2026 02:19
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Batch 3 of
ROADMAP.md. This is stacked on #3 (batch 2), so it targets that branch and the diff shows only batch 3. Merge #3 first, then change this PR's base tomaster(GitHub does it automatically if the batch 2 branch is deleted on merge).Changes
CollisionListenergetscollisionEnter(with, manifold)(the first step two bodies touch) andcollisionExit(with)(the first step they don't), alongside the existing per-contactcollision. Sensors get them too.Rigidbody::setCollisionLayerandsetCollisionMask. Two bodies collide only if each one's layer is in the other's mask (canCollideWith).World::raycasttakes an optional mask.World::isTouching(a, b)reports the current contact state.ALL_LAYERSis the default mask.setPosition, thetpcommand) update their grid cells at the start of each step. Before, the broad phase saw them in their old cells for one step, so they missed collisions in their new place.Entity::killand~Entitymark the entity dead before ending components, andScene::~ScenecallsWorld::clearContacts()first, so dying entities and scene teardown get no exit events.collisionEnterand the previous frame's speed, because velocities read inside callbacks are now post-solve.Behaviour changes
collisioncallbacks run after the solver rather than during the narrow phase, so a velocity read there is the resolved one.Testing
tests/test_collision_events.cppcovers:🤖 Generated with Claude Code
https://claude.ai/code/session_015cNAkNqoDWA5gFReD1AsqV
Generated by Claude Code