I'm trying to implement the usual continuous collision detection for my pong game, but I'm not sure if I am realizing or understanding this right. AFAIR continuous collision detection is used for fast-moving objects that can pass through another object that bypasses conventional collision detection.
So I tried, because the only fast moving object that I have is the ball, I just need the position of the ball, its speed and the position of the object with which we are comparing.
From this I realized that it would be better, for example, if the speed of the ball indicated that it was moving to the left, I would compare it with the greatest reference to the rightmost border of another object. From this, I would take a step by adding the speed of movement to the leftmost border of the ball and compare to make sure that it is larger than other objects associated with the right. This would indicate that there is no left right collision.
I have something somewhat working, but, unfortunately, the ball starts to jump normally for a while, then it acts as if it gets into the oar when nothing happens.
I'm a little lost, any help would be appreciated!
static bool CheckContinuousCollision(PActor ball, PRect ballRect, PActor other, PRect otherRect) { PVector ballMoveSpeed; int ballXLimit; int ballYLimit; ballMoveSpeed = ball.moveSpeed; // We are moving left if ( sgn(ball.moveSpeed.x) < 0 ) { ballXLimit = std.math.abs(ballMoveSpeed.x) / 2; for ( int i = 0; i <= ballXLimit; i++ ) { if ( ballRect.Left < otherRect.Right && otherRect.Left < ballRect.Left) { return true; } ballRect.Left -= i; } } //We are moving right if ( sgn(ball.moveSpeed.x) > 0) { ballXLimit = std.math.abs(ballMoveSpeed.x) / 2; for ( int i = 0; i < ballXLimit; i ++ ) { if ( ballRect.Right > otherRect.Left && ballRect.Right < otherRect.Right ) { return true; } ballRect.Right += i; } } // we are not moving if ( sgn(ball.moveSpeed.x) == 0) { return false; } }
source share