- #1
Kiltedboy
- 1
- 0
Hi First Post so go easy.
I am teaching a programming course for kids between 10-14.
We are using scratch which is a sprite animator.
We are trying to make a breakout game (you know the one where you break block with a ball)
We have a ball sprite that we can easily bounce around the screen as there is a build in function called "If on edge,bounce".
The issue we are having is when the ball collides with another sprite (a block or the paddle).
We would like to know if there is an equation that would work for all collisions so that,
The angle of the ball after the collision is equal and opposite to the angle of the ball before the collision.
e.g. If the ball is moving from left to right and up the screen and collides with block at a 25 degree angle, it continues left to right but leaves the block at a 25 degree angle but is now moving in a downward direction.
Here is what we know ,
The direction of the sprite in degrees. This is measured between (-179 and 180)
0 degrees is North (up)
90 degrees is East (right)
180 degrees is South (down)
-90 degrees is West (left)
We can turn a sprite either left or right by a number of degrees
So in my 25 degree example above the spirtes direction would be 25 degrees (NE) before the collision and 115 degrees (SE) after the collision,
If the sprite were to be traveling right to left :
Its direction would be -25 degrees (NW) before the collision and -115 degrees (SW) after the collision
Can one of you Physics Geniuses come up with an equation that would work for all collisions?
i.e. on all 4 sides of the block from all possible directions ?
Thanks in advance,
Drumbrae Coder Dojo Pupils
I am teaching a programming course for kids between 10-14.
We are using scratch which is a sprite animator.
We are trying to make a breakout game (you know the one where you break block with a ball)
We have a ball sprite that we can easily bounce around the screen as there is a build in function called "If on edge,bounce".
The issue we are having is when the ball collides with another sprite (a block or the paddle).
We would like to know if there is an equation that would work for all collisions so that,
The angle of the ball after the collision is equal and opposite to the angle of the ball before the collision.
e.g. If the ball is moving from left to right and up the screen and collides with block at a 25 degree angle, it continues left to right but leaves the block at a 25 degree angle but is now moving in a downward direction.
Here is what we know ,
The direction of the sprite in degrees. This is measured between (-179 and 180)
0 degrees is North (up)
90 degrees is East (right)
180 degrees is South (down)
-90 degrees is West (left)
We can turn a sprite either left or right by a number of degrees
So in my 25 degree example above the spirtes direction would be 25 degrees (NE) before the collision and 115 degrees (SE) after the collision,
If the sprite were to be traveling right to left :
Its direction would be -25 degrees (NW) before the collision and -115 degrees (SW) after the collision
Can one of you Physics Geniuses come up with an equation that would work for all collisions?
i.e. on all 4 sides of the block from all possible directions ?
Thanks in advance,
Drumbrae Coder Dojo Pupils