Skip to content

Commit

Permalink
fix: CompositeCollider behavior affecting TileMap w/Realistic Solver (#…
Browse files Browse the repository at this point in the history
…3322)


Fixes issue where the realistic solver gets confused with TileMaps mentioned in the discord https://discord.com/channels/1195771303215513671/1320140196372676692

The issue causes massive overcorrection because it _appears_ to the solver that the collider in a composite is further away from the contact than it actually is.


https://github.com/user-attachments/assets/45bceff6-ab06-40b7-9c91-a4886505c124


In the fix we shift the collider local side by the offset (which is what is used in composites to position relative to the transform). This gives an accurate pos for the contact point


https://github.com/user-attachments/assets/db83f756-8aa0-43a0-99da-72a7bebbb772
  • Loading branch information
eonarheim authored Dec 28, 2024
1 parent d232f51 commit 1827afb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).

### Fixed

- Fixed issue with CompositeCollider where large TileMaps would sometimes causes odd collision behavior in the Realistic Solver when the body & collider components are far apart in a TileMap.
- Fixed crash on Xiaomi Redmi Phones by lazy loading the GPU particle renderer, GPU particles still do not work on these phones
- Add warning if World.add() falls through! This is caused by multiple versions of Excalibur usually
- Fixed CollidePolygonPolygon crash with some defense against invalid separation
Expand Down
12 changes: 9 additions & 3 deletions src/engine/Collision/Colliders/CollisionJumpTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ export const CollisionJumpTable = {
return [];
},

FindContactSeparation(contact: CollisionContact, localPoint: Vector) {
FindContactSeparation(contact: CollisionContact, localPoint: Vector): number {
const shapeA = contact.colliderA;
const txA = contact.bodyA?.transform ?? new TransformComponent();
const shapeB = contact.colliderB;
Expand All @@ -314,10 +314,16 @@ export const CollisionJumpTable = {
let side: LineSegment;
let worldPoint: Vector;
if (contact.info.collider === shapeA) {
side = new LineSegment(txA.apply(contact.info.localSide.begin), txA.apply(contact.info.localSide.end));
side = new LineSegment(
txA.apply(contact.info.localSide.begin).add(shapeA.offset),
txA.apply(contact.info.localSide.end).add(shapeA.offset)
);
worldPoint = txB.apply(localPoint);
} else {
side = new LineSegment(txB.apply(contact.info.localSide.begin), txB.apply(contact.info.localSide.end));
side = new LineSegment(
txB.apply(contact.info.localSide.begin).add(shapeB.offset),
txB.apply(contact.info.localSide.end).add(shapeB.offset)
);
worldPoint = txA.apply(localPoint);
}

Expand Down

0 comments on commit 1827afb

Please sign in to comment.