How to create a BOUNCY ball???
Author |
Message |
mg_angel
|
Posted: Mon Oct 17, 2005 5:01 pm Post subject: How to create a BOUNCY ball??? |
|
|
PLEZ.... Help me!!!! I need to create a bouncy ball for my computer and information science project by using randomization, but I don't know how to make the ball to bounce. Please help me!!! If you know how, please post your code here!!!! Thank you SO MUCH!!!! |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
Cervantes

|
Posted: Mon Oct 17, 2005 6:23 pm Post subject: Re: How to create a BOUNCY ball??? |
|
|
mg_angel wrote: Please help me!!! If you know how, please post your code here!!!!  Thank you SO MUCH!!!!
We've better things to do than do your homework for you. We help, not do.
mg_angel wrote: PLEZ.... Help me!!!! I need to create a bouncy ball for my computer and information science project by using randomization, but I don't know how to make the ball to bounce.
First, a bouncing ball is not very random. Could you explain how you are supposed to make this random?
Second, you'll have to work with velocities and accelerations. Each time through your loop, subtract a certain value to the y velocity of your object. This serves as acceleration. Each time though your loop, add the x velocity to the x position of the ball, and add the y velocity to the y position.
Third, when the ball hits the floor (ie. the y value is less than some value), reverse the y velocity. This is most easily achieved by multiplying it by -1. If you want the ball to lose some energy, multiply it by something closer to zero, such as -0.99. |
|
|
|
|
 |
mg_angel
|
Posted: Tue Oct 18, 2005 6:25 am Post subject: (No subject) |
|
|
Hey, Cervantes Pirate Mod. I really appreciate ur help, but... the bouncy ball I have to create is MUCH less complicated than u think.
First of all, I don't need to change the speed of the ball, I just want it to bounce continually, of course it has to bounce from a different direction to another.
Secondly, forget the randomization part, I already figured out how to do that, so now, all I need to know is how to make the ball to bounce continually on the screen.
Thankx....  |
|
|
|
|
 |
jamonathin

|
Posted: Tue Oct 18, 2005 6:31 am Post subject: (No subject) |
|
|
What you need to is make two variables tha represent the ball-X value and ball-Y value.
Then make two more variables to represent the speed of the bounce. now you can either assign a variable to the gravity or just use the number without assigning it a variable.
Create a loop, and in that loop have your ball-Y value always adding the speed of the bounce.
Then you must always be subtracting gravity from the speed of the bounce variable. If that "speed of bounce" variable ever gets = to 0 or less than 0have it reset to its default value. |
|
|
|
|
 |
Cervantes

|
Posted: Tue Oct 18, 2005 1:20 pm Post subject: (No subject) |
|
|
Or, are you referring to a situation with no gravity, where the ball moves at a constant speed and bounces off all four walls?
If so, you need variables to store x and y positions and variables to store x and y velocities. Add velocities to corresponding positions.
You need some collision detection:
code: |
if x > maxx or x < 0 then
vx *= -1 %reverse x velocity
|
Do similarly for y. |
|
|
|
|
 |
MysticVegeta

|
Posted: Tue Oct 18, 2005 1:52 pm Post subject: (No subject) |
|
|
OK this about this ->
Make a "for" loop till the distance that want covered by the ball.
If you need to make the ball go up, then change the y to the loop variable.
And make sure you make an erasing ball with the color of your background.
Add a delay to the loop. |
|
|
|
|
 |
Cervantes

|
Posted: Tue Oct 18, 2005 5:21 pm Post subject: (No subject) |
|
|
MysticVegeta wrote:
Make a "for" loop till the distance that want covered by the ball.
If you need to make the ball go up, then change the y to the loop variable.
Using a for loop to move a ball is never a good idea. First, it prevents other things from occuring at the same time (if you wanted it to happen, you'd have to edit your code and copy&paste it inside this loop as well). Second, it does not conform to the properties of a ball object. It appears to describe the motion of the ball, but it leads to now explanation of why. And it does not lead to an understanding of objects.
Consider a ball thrown through the air. Sure you could use a for loop to iterate through different x values and calculate y based on a parabolic equation, but that only describes how the object behaves. Not why. To explain why, you need to apply accelerations to velocities and velocities to positions (and you need to understand that gravity is the accelerator).
It's like kinematics vs. dynamics. |
|
|
|
|
 |
MysticVegeta

|
Posted: Tue Oct 18, 2005 6:27 pm Post subject: (No subject) |
|
|
Its always good for beginners though dont you think? |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
|
|