Created
October 28, 2014 14:57
-
-
Save izackp/016963a953493d44c51e to your computer and use it in GitHub Desktop.
Sweeping 2D Collision Detection Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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