2D Collision Study

N 人看过

Circle / Rectangle Collision

Circle Collision

Circle collision is much easier, only need to determine distance between centers > sum of radius.

circle

Axis-Aligned Bounding Box

Determine 2 rectangles without rotation is collided or not.

Check the bounds of each rectangle with width & height
That is check :

All of above conditions are satisfied.

AABB

AABB in Unity

Bounds

Represents an axis aligned bounding box.
An axis-aligned bounding box, or AABB for short, is a box aligned with coordinate axes and fully enclosing some object. Because the box is never rotated with respect to the axes, it can be defined by just its center and extents, or alternatively by min and max points.

Separate Axis Theorem (SAT)

Separating Axis Theorem (SAT for short) states if you are able to draw a line to separate two polygons, then they do not collide.

SAT :

If we can find out separate axis,
two polygons doesn’t collide each other.

Algorithm:

Find out separate axis of 2 polygons.

How to find SAT?

Just like Axis-Aligned Bounding Box,
project each vertice onto each edge.

(AABB method use x-y axes to detect)

Finding SAT

  • It’s not reasonable to search all axes for finding a SAT.
  • Select the candidate axes for finding SAT!
  • The axes must test are the normals of each edges from shapes.

Finding SAT Algorithm

  1. Find all normals from each shape
  2. Find all project point for all vertices on each normal
  3. Find if there is at least 1 separate axis or not.
    (projection1.max > projection2.min && project2.max > projection.min)

Find Minimum Translation Vector

Tracking the the minimum overlap and axis when we finding SAT.
Use this vector to separate shapes.
from internet

Still some problem…

Tunneling

Discrete simulation can lead to missed collisions and tunneling. In this case the ball falls out of the world.

Some of CCD resources:

Unity : Continous Collison

Erin Catto : Continous Collision