Jump to content
  • Advertisement
Sign in to follow this  
ProblemBaby

Collision Detection

This topic is 5056 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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!