Var bounceAngle = normalizedRelativeIntersectionY * MAXBOUNCEANGLE var normalizedRelativeIntersectionY = (relativeIntersectY/(PADDLEHEIGHT/2)) I call this the "relative intersect" because it is in "paddle space" now, the ball's intersection relative to the middle of the paddle. If the paddle is 10 pixels high, this number will be between -5 and 5. Take the middle Y value of the paddle, and subtract the Y intersection of the ball. var relativeIntersectY = (paddle1Y+(PADDLEHEIGHT/2)) - intersectY And it always travels at a constant speed. If the ball hits the paddle right in the center, it is sent away exactly horizontal if it hits right on the edge, it flies off at an extreme angle (75 degrees). Here's the relevant logic I used on the pong on my homepage: (please go play it before reading, so that you know the effect I'm achieving with the following code)Įssentially, when the ball collides with the paddle, its direction is completely disregarded it is given a new direction according to how far from the center of the paddle it collided.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |