dimforge / dimforge/nphysics

Some issues in collision resolving.

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

Description

Hi!

Characters in my game presented in physics world as a Ball, I call rigidbody.set_linear_velocity() every frame, to control them. And sometimes characters can pass between 2 cuboid walls like this:

![Image](https://i.gyazo.com/23449b9819e7e1298109d29e9e417083.png)

For example, there is 2 cuboids, on (-0.5, 0) and (0.5, 0), timestep 1/10 and ball with radius 0.3 on position (0.0, 1.2), setting it linear velocity after every step to (0, -5.0):

Ball: Translation { vector: Matrix { data: [0.0, 1.2] } }
Ball: Translation { vector: Matrix { data: [0.0, 0.70000005] } } // Collision happens on next frame
Ball: Translation { vector: Matrix { data: [0.0, 0.95000005] } } // Collision happens and resolved
Ball: Translation { vector: Matrix { data: [0.0, 0.45000005] } } // Going through cuboids
Ball: Translation { vector: Matrix { data: [0.0, -0.049999952] } } // Going through cuboids
Ball: Translation { vector: Matrix { data: [0.0, -0.54999995] } } // Going through cuboids
Ball: Translation { vector: Matrix { data: [0.0, -1.05] } } // Finally passing through
Ball: Translation { vector: Matrix { data: [0.0, -1.55] } }

If i change a start position of a ball slightly to (0.0, 1.3) - it can't pass through:

Ball: Translation { vector: Matrix { data: [0.0, 1.3] } }
Ball: Translation { vector: Matrix { data: [0.0, 0.79999995] } }
Ball: Translation { vector: Matrix { data: [0.0, 1.05] } }
Ball: Translation { vector: Matrix { data: [0.0, 0.54999995] } }
Ball: Translation { vector: Matrix { data: [0.0, 0.81401926] } }
Ball: Translation { vector: Matrix { data: [0.0, 1.0640192] } }

Also, if move it a little right to (0.01, 1.2) and *increase* speed to 5.01, ball can't pass too.

I understand that behavior depends on timestep and speed, but it looks like that position can be correctly resolved on this steps of first example:
Ball: Translation { vector: Matrix { data: [0.0, 0.95000005] } } // Resolved
Ball: Translation { vector: Matrix { data: [0.0, 0.45000005] } } // Going through cuboids
Ball: Translation { vector: Matrix { data: [0.0, -0.049999952] } } // Going through cuboids

And in the game, this things can happens on low velocities.
I'm playing with integration parameters (and setting ERP *iterations to max values), and nothing helps.

UPD:

Also, I iterate through all contact events during every frame, and there is a really strange things:
Cuboid(0) - 1.0x1.0 static Cuboid placed on -0.5, 0
Cuboid(1) - 1.0x1.0 static Cuboid placed on 0.5 0
Ball(2) - Ball with radius(0.3) placed on 0.0, 1.2
Default integration parameters, without gravity, timestep - 0.1
Every frame after step linear velocity setted to (0.0, -0.5) on the ball rigidbody

Frame 0- Ball: [0.0, 1.2]
Frame 1- Ball: [0.0, 0.70000005]
Frame 2- Ball: [0.0, 0.95000005] // Collision happens during this frame and have been resolved, but contacts only started and not stopped
Contact between Ball(2) and Cuboid(0): Started
Contact between Ball(2) and Cuboid(1): Started
Frame 3- Ball: [0.0, 0.45000005] // Shapes intersected, but contacts stopped (they must be stopped in previous frame) and not started (?)
Contact between Ball(2) and Cuboid(0): Stopped
Contact between Ball(2) and Cuboid(1): Stopped
Frame 4- Ball: [0.0, -0.049999952] // We are still in collision, but there is no started contacts
Frame 5- Ball: [0.0, -0.54999995] // And we are still in collision
Frame 6- Ball: [0.0, -1.05] // Our ball passing through cuboids and away from them, contacts started just now
Contact between Ball(2) and Cuboid(0): Started
Contact between Ball(2) and Cuboid(1): Started
Frame 7- Ball: [0.0, -1.55]
Contact between Ball(2) and Cuboid(0): Stopped
Contact between Ball(2) and Cuboid(1): Stopped

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.