Skip to content

Instantly share code, notes, and snippets.

@nklsrh
Created July 10, 2013 02:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nklsrh/5963052 to your computer and use it in GitHub Desktop.
Save nklsrh/5963052 to your computer and use it in GitHub Desktop.
// if ball is aligned with paddle1 on x plane
// remember the position is the CENTER of the object
// we only check between the front and the middle of the paddle (one-way collision)
if (ball.position.x <= paddle1.position.x + paddleWidth
&& ball.position.x >= paddle1.position.x)
{
// and if ball is aligned with paddle1 on y plane
if (ball.position.y <= paddle1.position.y + paddleHeight/2
&& ball.position.y >= paddle1.position.y - paddleHeight/2)
{
// ball is intersecting with the front half of the paddle
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment