Sign in to follow this  

Collision Detection

This topic is 4841 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

Hi Do anyone know a good tutorial or can help me right here! I want to do a Collision Detection test between a Circle and Rectangle (that isnt rotated). It dont have to take care of edges I just want to have a simple one. The big problem is that both is moving so I dont know how do it. The thing I need to know is only which side the ball collided with in the rectangle. this is the variables: xBall, yBall, BallRadius, xBallVel, yBallVel xRect, yRect, RectHalfWidth, RectHalfHeight, xRectVel, yRectVel. Is it possible to do such a test in one step??? plz plz help!

Share this post


Link to post
Share on other sites
Source code for finding the first time of contact and the contact point between a moving circle and an oriented rectangle are at (http://www.magic-software.com), the Source Code tab, then the Intersection tab, files WmlIntrCir2Box2.{h,cpp} (and various supporting files). I also have an application to illustrate this. From the Source Code page, select Applications, Application Types: Miscellaneous, then "Dynamic intersection of a moving circle and a rectangle". Computing the first time/point of contact is trickier than you might think.

Share this post


Link to post
Share on other sites
Ok i think ive a plan how to do this!
But I must ask only this Iam doing a kind of pong style game.
My idea is to "stop" the ball when it hits something so I dont have to do all tests once more in that frame.

this is for example the check if the ball hits the bottom.

xAdd = FixedMul(COS[Direction], Speed);
yAdd = FixedMul(SIN[Direction], Speed);

if (bally + radius + yAdd > BOTTOM)
{
Direction = -Direction;
yAdd = FixedMul(xAdd, FixedDiv(((BOTTOM - radius) - bally), zAdd));
xAdd = BOTTOM - (bally + radius)
}

ballx+=xAdd;
bally+=yAdd;

It works but I thought this should make it quite smooth, well it is if the balls move in about 20 pixels per second.
Is it an unsmooth technique or is the formula wrong?
Or do anyone have better ideas??
Plz HElp

Share this post


Link to post
Share on other sites

This topic is 4841 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this