fokion.blogg.se

Bouncing balls game stick figure
Bouncing balls game stick figure







Yes, I like this: velocity2 = velocity1 + ( paddle_velocity * some_constant ) normalize the post-collision velocity and multiply it by the length of the pre-collision velocity to prevent that. this is sorta like the paddle being rough, the collision being non-instanteanous, and 'pushing' the ball sideways slightly if the paddle moves fast enough.īear in mind, that this will add energy to your system ( or remove it ) over time. The effect here, is that if the paddle moves in the horizontal direction that the ball is moving, the ball will bounce 'flatter', if the paddle moves in the opposite horizontal direction, the ball bounces upwards more sharply. Try this: velocity2 = velocity1 + ( paddle_velocity * some_constant ) Like I say, I may be wrong :Pįor a quick solution, instead of doing this with the ball velocity after a bounce: velocity2 = velocity1

#BOUNCING BALLS GAME STICK FIGURE CODE#

Alot of basic collision detection code assumes that a collision happens instantanously, and I believe ( although I may be completely wrong on this! ) that if a perfect sphere bounces off a perfect plane, that the velocity of the plane that is in the plane doesn't affect the bounce angle of the sphere. I am not sure if that's how breakout always is. Given any initial starting angle, and assuming that the player is 'perfect', and assuming that you don't handle corners of the paddle in any special way the movement of the ball will always be exactly the same the game is deterministic with a perfect player. Any other angle will have slightly more possible results.īut. The quick trick you describe ( inverting one of the components of the moving object's velocity on a bounce with a plane ) works irrespective of the initial angle that the ball is travelling at if you start the ball moving at any angle other than 45 deg, then bounce angles will be a little more 'varied', because only 45 deg will invert as itself. The only areas of the paddle that ARE different are the corners, do you model that accurately? The position of the paddle when the ball hits it is wholely irrelevant - the paddle is the same all over, flat, and moves in a constrained direction ( in its own plane ), so any moving point on the paddle is 'identical' to any other point in terms of any calculation you perform. How do I use the factors I just mentioned along with any others I might need to take into consideration to write the code for this? I look online for some tips but I couldn't find much that gave an algorithm and explained it. How do I calculate the change in angle based on the movement of the paddle, the place the ball hits the paddle, and the angle the ball is currently traveling at. So I came to the conclusion that the only way to change the angle is when the ball collides with a moving object, i.e., the paddle. The way I see it, bouncing against non-moving blocks will not change the direction that the ball is moving (that is angle-wise, obviously it will bounce off, but the angle that the ball is moving won't ever change to anything other than 45, 135, 225, or 315 degrees. But now I want to make a game where the ball moves not just at 45 degree angles. Just reverse the x or y movement everytime you hit something.

bouncing balls game stick figure bouncing balls game stick figure bouncing balls game stick figure

The way I've made breakout games before was to have the ball only move at 45 degree angles. Hey, so I'm making a Breakout game in C++ w/ DirectX, and I'm having some trouble thinking of the ball bouncing physics.







Bouncing balls game stick figure