PDA

Click to See Complete Forum and Search --> : Ball bounce inside circle?



jmdesigns
09-09-2002, 12:44 PM
Hello everyone, I have spent the last few days researching what is needed to complete a project I am working on. I am still in planning stages and pretty much have everything drawn out except how to go about a math problem.

It seems like everyone out there is working on a Mini-Golf game, and well, after some vacation inspiration - I plan to try my hand at it.

I have seen other examples using straight walls, 90 degree angles, and such. This wouldn't be a problem..

My ultimate goal is to be able to create holes with curved as well as straight walls.

I figure that if a Billiards game can calculate the angle the cue ball bounces from the circular target ball, this should be do-able as well. And it could even have some pretty exact calculations because there is only one ball in a game like this and shouldn't bog down the CPU like a Billiards game would..

Can anyone point me to some tutorials/examples or toss out some information that might get me along my way? I would like to get something that is as close at true to life as possible without massive headaches for every hole I create.

Also, for each hole that I create, would I need to create using curves and lines in AS in order to let AS know where my walls are, or would I be able to sketch out a design in Freehand and import it into flash with little follow-up AS?

I feel that I have a good handle on AS, but am quickly learning Math aspects. I have been through a few chapters which explain straight-wall bounce angles (pong for example) and hope that my request can be achieved with a few more lines of code.

Sorry for the long post, I can post a few example sketches of the courses I wish to create if needed.

Thank you for your help!
-John

JacoB2
09-22-2002, 10:59 AM
Hi

I am having the exact same problem. I am making a ball game that is like a ping-pong ball game, only the ball bounces inside of another ball and it has three flippers and then you can rotate the three sides (in a circle) and make the ball bounce back.

I am struggling with keeping the ball inside the circle, I want it to be "game over" when it (ball) has moved outside the radius.

I think I might have a solution for this, I havent worked with arrays before but I assume that if you could work out all the x and y coordinates to all the angles (0-360) store them in an array. Then work out the appropriate quarters for e.g 0-90 degrees = Ball X > XCoordinate[i] + CenterX && BallY < YCoordinate[k] - CenterY = then game over and so forth.

Im not sure if this would work and there must be an simpler way to do this. Thats how far I have gotten but also im not sure if all that calculations would slow down the processor.

if I find an solution I would let you know, if this works let me know or if you know of another way.

swills
09-24-2002, 09:06 AM
JacoB2

Why not keep it simple and, having the coordinates for the ball centred at the centre of the bigger circle, find out the distance the ball is from the centre using pythagoras's theorum. If this distance is larger than the readius of the larger circle then it has hit or passed the outer circle.

I've done the same in........

http://194.131.128.207/flash/circlebounce/Movie1.swf

............but then I make it bounce rather than the "game being over"

jmdesigns

to "bounce" off a curved surface, all you need to find is the tangent of the curve at the point of impact, and use this tangent as the "flat surface" to bounce off of. So to find the tangent you'd have to know the equation of the curve, or even easier if you use circles(or part-circles) and know the centre point of the circle to use in a simple equation - the products of the gradients of the (radius) at the point of impact and the (tangent) equals -1. Bit of trig and away you go!

swills

JacoB2
09-24-2002, 04:16 PM
Hello

Thanks ..wow...I like what you have done. I have found a very simple way to make it "game over" in a link from someone.

The other problem now is the way I make the ball bounce back from the three sides. I use collision detection (hitTest) and coordinates to determine which side it must bounce back for e.g (side1)-if (BallY < 190 && this.hitTest(_root.One)) then YSpeed *=-1;I have made many statements like this for all the quarters of the circle and for speed i used a function that makes a random number between two numbers. I have copied this code then into the other two sides (that hit the ball) back . Is this the correct way?
Are there any other methods on doing this.

To make it bounce back from the blocks (in middle). I again use hitTest but this time with relation to the speed of the ball for e.g if the ball hits the blocks and YSpeed > 0 , then the ball must bounce back (up). I have not worked it out completely but seems to work ok. Is this how you would do it or are there other methods...

Thanks

swills
09-24-2002, 04:38 PM
I'm confused - what 3 sides? A circle only has one "side".

Post a link to what you have so far so we can get a better idea of what you're after.

swills

jmdesigns
09-24-2002, 05:01 PM
Thank you Swills for your info! I remember seeing your bounce sample and it looks good!

I took some more time and researched the ways to accomplish this more, when it seemed like hitTest would be the easiest I was put back on the correct Maths path by the guys in the games forum. I guess I need to re-learn Trig and the Maths after all.

I have started back up heavy into trying to pick up the tools necessary for Maths in flash. While Sams' Learn AS in 24 hours for Flash MX has taught me many Maths functions including Cos and Sin I have yet to see anything on good atan use in Flash besides the AS Dictionary.

Are there any good flash/tangent tutorials out there? I'm sure I can probablly learn it by looking at samples.. I have been referred to Bit-101 for samples, and I even see that he has some excellent samples in the Friends of Ed book on Flash Math Creativity.

Wow, and I never thought I would use this stuff when I graduated from HS! :)

Jacob: Looks like we're in somewhat the same boat! Good luck with your project, sounds neat, i'd love to see your game when completed!!

JacoB2
09-25-2002, 01:44 PM
Hello

Sorry for the confusion. Here is the url as I got it so far:

http://home.wol.co.za/~20077423/movementNew2.swf

There are still many problems with it, some of the graphics I just put in for clarity (the hit states of the sides) .

Ok, so I got it almost completely functional but there are still errors for e.g there are places where the code overlap causes the ball to jump left/ then right or up/down. Mostly in the middle parts. And the ball only bounces up so far, still need to do the other sides, this is the part that I am most uncertain off.

Also the restart button doesnt work yet, will look into that later.

For now have a look and thanks for all the help so far

JacoB2
09-28-2002, 11:26 AM
Hello

ok....so its been a couple of days now, and I just cant seem to find a solution for my problem. I have tried just about everything.

Here is how it looks so far, forgot to mention you move the three sides with left/ right.

http://home.wol.co.za/~20077423/whatEver.swf

Another thing, I have tried to use other methods of collision detection but it doesnt seem to work for e,g
if (BallY > BlockY - 9) { etc. , this problem is futher exagerated by the fact that the blocks rotate.

any help would be so appreciated

thanks