dimforge / dimforge/nphysics

Contact between a ball and cuboid sometimes and has no contact pair

Open
#255 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
1.6k
Forks
120
PR merge metrics
No merged PRs in 30d

Description

Not sure if this is only reproducible with a `Ball` hitting a `Cuboid`, but I have not tested two `Cuboid`s or other shapes.

Essentially, with my cuboid colliders and ball rigidbody, every once in a while the ball will collide and have no contact pair when I query. This means I can't react to the collision properly and my game just kind of breaks. It is strange though, because the rigidbody is reacting to the collision, either stopping in its place, or sliding along the box collider that it hit.

I made my game repo public with a repro branch [here](https://github.com/Dooskington/brickbonker/tree/cb5b0953572aa03f1f6b0135ce2f596d5376a513), and the physics code is [here](https://github.com/Dooskington/brickbonker/blob/cb5b0953572aa03f1f6b0135ce2f596d5376a513/src/game/physics.rs#L456). The ball (created in `ball.rs`) has a mass of 1.0 and the rest of the colliders and paddle are just boxes set up in `game/mod.rs`.

If you manage to compile and run it and want to actually repro, use A/D or Left/Right to move the paddle, and spacebar to launch the ball. This seems to be easiest to repro if you just bounce the ball back and forth on the Y axis, hitting the paddle (collider index 0) and the brick directly above. Eventually, the ball will reflect strangely or stop entirely and you can observe that no contact pair was found:
```
contact started: handle1: Index { index: 54, generation: 0 }, handle2: Index { index: 0, generation: 0 }
No contact pair found for collision!
```

If you enable the `println!()` under the `physics.step()`, we can see that this isn't a case of a contact event starting and stopping on the same step (there would be a 'contact stopped' logged):
```
step
contact started: handle1: Index { index: 54, generation: 0 }, handle2: Index { index: 0, generation: 0 }
No contact pair found for collision!
step
step
```

Messing with the ccd parameters doesn't seem to help. Disabling CCD seems to improve the situation but does not fix it.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by compiling and running the linked brickbonker repro branch, then inspect the physics query at src/game/physics.rs around line 456. Compare the contact-start logging with physics.step(), and review ball.rs and game/mod.rs for the ball and cuboid setup. Done means the reported collision consistently provides a contact pair instead of logging that none was found.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
game-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.