How to fix circle and rectangle overlap in collision response?

后端 未结 3 976
不思量自难忘°
不思量自难忘° 2020-12-13 05:29

Since in the digital world a real collision almost never happens, we will always have a situation where the \"colliding\" circle overlaps the rectangle.

How

3条回答
  •  离开以前
    2020-12-13 05:59

    It's a non-linear problem, right?

    You take a time step and move the ball by its displacement calculated using velocity at the start of the step. If you find overlap, reduce the step size and recalculate til convergence.

    Are you assuming that the balls and rectangles are both rigid, no deformation? Frictionless contact? How will you handle the motion of the ball after contact is made? Are you transforming to a coordinate system of the contact (normal + tangential), calculating, then transforming back?

    It's not a trivial problem.

    Maybe you should look into a physics engine, like Box2D, rather than coding it yourself.

提交回复
热议问题