Jump to content
  • Advertisement
Sign in to follow this  
phil67rpg

collision detection

This topic is 3861 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am programming a breakout clone and have the ball and bricks and the paddle, all I need is help in implementing the collision detection for the ball and the paddle and the bricks,

Share this post


Link to post
Share on other sites
Advertisement
Well...
If you just need to find collisions for two boxes just do this...

if x1 + width1 > x2 and y1 + height1 > y2 and x1 < x2 + width2
and y2 < y2 +height2 then collision!

it may not work correctly because I am a little rusty in 2D but this are the basis.
(its written in pseudo-code. dont just copy and paste).

Share this post


Link to post
Share on other sites
The simplies way is to check everything as per frame...
This would give you the best quality and the worse FPS

you should have a

I assume you would have the following handy
Object: bounded by a set of vertices and
a set of three vertices define a plane (a triangle)
your triangle ranges from 0 to pPlane[k];
Curl your vertices to get the norm.

your ball position... "pPosition" and radius of that ball


bool Collision(PlaneDataTYPE pPlane, PositionVectorDATATYPE pPosition)
{
for ( int i = 0; i < k; i++ )
if ( D3DXPlaneDotCoord( &pPlane, pPosition ) + radius < 0 )
// radius is your ball / sphere radius
return FALSE;

return TRUE;
}


if the function evaluates true then you have a collision, else, your ball roams free

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!