1
General / Re: C++ SFML, Circular Movement - Help!
« on: September 23, 2013, 09:58:35 pm »
Balls getting stuck is a typical problem in this kind of game. Basically you have to make sure that the ball is headed towards a certain object before trying to calculate a collision against it. If the ball is not even headed against the object you can simply ignore the rest of the computation.
So, if the ball's velocity vector and the normal of the surface are less than 90 degress apart, there can be no collision (beware, there are two normals for a line segment in 2D, you need the one pointing "inside" the circular world, but I suppose you already figured that out). This is a fairly simple check.
To do it, you need to find the cosine of the angle between the two vectors (ball velocity and surface normal) and if it is equal to or more than zero (angle is between -90 and 90 deg) there can be no collision. You can compute this using the dot product. Here's an explanation for 3D vectors: http://www.wikihow.com/Find-the-Angle-Between-Two-Vectors
So, if the ball's velocity vector and the normal of the surface are less than 90 degress apart, there can be no collision (beware, there are two normals for a line segment in 2D, you need the one pointing "inside" the circular world, but I suppose you already figured that out). This is a fairly simple check.
To do it, you need to find the cosine of the angle between the two vectors (ball velocity and surface normal) and if it is equal to or more than zero (angle is between -90 and 90 deg) there can be no collision. You can compute this using the dot product. Here's an explanation for 3D vectors: http://www.wikihow.com/Find-the-Angle-Between-Two-Vectors