Collision Detection

Started by
3 comments, last by FireNet 19 years, 7 months ago
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!
Problems every where
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.
This tutorial is in flash, and the theory is very good, check it out:

Collision Detection
My site Jvitel.com
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
Problems every where
Quote:Original post by J_Vitel
This tutorial is in flash, and the theory is very good, check it out:

Collision Detection


Very nice tut J_Vitel.
______________________________________________________________________________________________________
[AirBash.com]

This topic is closed to new replies.

Advertisement