Skip to content

Instantly share code, notes, and snippets.

@izackp
Created October 28, 2014 14:57
Show Gist options
  • Save izackp/016963a953493d44c51e to your computer and use it in GitHub Desktop.
Save izackp/016963a953493d44c51e to your computer and use it in GitHub Desktop.
Sweeping 2D Collision Detection Example
float x = 5.0f;
float y = 5.0f;
float destX = 25.0f;
float destY = 30.0f;
float diffX = abs(destX - x);
float diffY = abs(destY - y);
float scale = 0.0f;
if (diffX > diffY)
scale = diffX;
else
scale = diffY;
float xStep = diffX / scale;
float yStep = diffY / scale;
while (x != destX && y != destY)
{
x += xStep;
y += yStep;
checkForCollision();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment