PDA

View Full Version : gravity



ilyaslamasse
January 26th, 2002, 08:33 AM
I have programmed gravity a I could (with collision detection to make the ball bounce), but I have several problems :
- when it should stop bouncing, well, it still does, very small bounces. I think that this is because of my function that works like that : vel = vel*0.8 + distance(ball,ground) ;
- when the motion is too quick, the ball gets stuck IN the ground. I made it so that when the ball hits the ground, vel *= -1 ; to invert the speed. So when the motion is quick, to ball hits the bottom of the groudn, and then bounces on the top of the ground so it's stuck.

Any ideas ???

pom

eyezberg
January 26th, 2002, 12:42 PM
Gravity sucks, i want to FLY !!

ilyaslamasse
January 26th, 2002, 12:55 PM
So That's what I want : A flying SuperIlyas 0] that you can control, but there must be some gravity in it !!!!!

pom

ilyaslamasse
January 26th, 2002, 08:14 PM
Here's the result. Any idea ?
pom

thoriphes
January 26th, 2002, 08:36 PM
hope this helps:
<a href=http://www.danalu.com/thoriphes/gravity.swf>here</a>
if you need to see the fla, then let me know, but all the script in the movie is seen on the swf anyway...

suprabeener
January 27th, 2002, 02:54 AM
this site came up when i was looking for real equations:
http://library.thinkquest.org/16600/

it's a great site.

i made something, it's not really based of real equations like i'd hoped, but it's at least indicative. the slider adjusts the gravity.

<EMBED src="http://members.shaw.ca/rlinton/posts/gravity.swf" quality=high bgcolor=#FFFFFF WIDTH=300 HEIGHT=300 TYPE="application/x-shockwave-flash"></EMBED>

the code on ball is:
<font color="#000070">
onClipEvent(load){ _quality = "LOW"; // not really necessary y = _y; d = .985; // drag g = .5; // gravity}onClipEvent(enterFrame){// make sure we're not stoppedif(!stp){ // if our destination is beyond the barrier, and we're going down // i think the direction check will solve your problem if(y+ymov>270 && ymov>0){ // if we're just looping this frame, stop if(count<2) stp=1; y = 270; // invert direction with a little friction ymov*=-d; // reset the count count=0; }else{ count++; ymov += g; y+=ymov; ymov *= d; } _y=y;}}</font>

eyezberg
January 27th, 2002, 04:50 AM
Oh supra', my scripting god, this might be one for you:

www.friendsofed.com/books...index.html (http://www.friendsofed.com/books/flash_math_creativity/index.html)

seems to be new -and expensive- haven't had a chance to get a look yet..

ilyaslamasse
January 27th, 2002, 06:00 AM
Thoriphe, thank you very much, your script is clear as holy water (as always).
Supra, I don't understand the utility of count. Very interesting link by the way.
Eyez, that book looks awesopme. If you ever buy it ($50 !!, @#%$ !!), you know where to find me...

pom

ilyaslamasse
January 27th, 2002, 07:33 AM
OK, so here's the ultimate gravity simulation. And Supra, this one's based on physics law. Actually, I used Thoriphe's script to make it work since I don't understand how yours work.
Here's the lowdown : mass * acceleration = sum of the forces (here : weight only)
So acceleration = gravity constant G
and velocity = G*Time elapsed + original speed
And you get this :

eyezberg
January 27th, 2002, 07:41 AM
Where's the replay?
By the time the page is loaded, the anim is over :)

ilyaslamasse
January 27th, 2002, 07:53 AM
Couldn't do it... Dammit !! You got me, Austin Powers !
Any idea how to reset a timer ?
Austin
Ok got round it :

ilyaslamasse
January 27th, 2002, 08:09 AM
Why doesn't it work when you edit and add the "custom signature" ?
pom
Dammit !!!

ilyaslamasse
January 27th, 2002, 08:13 AM
I hate it !!!!
By the way, the ball seems to float a little bit because I set the gravity to 1 instead of 10.
pom

PS : By the way, I noticed that your ball can be dragged, Supra. But it doesn't keep its speed, it just falls down. Any idea how to solve that ?

ilyaslamasse
January 27th, 2002, 11:26 AM
I'm having fun, or should I say... phun ? 0] Now you can drad the ball and give it the speed you want.
pom

thoriphes
January 27th, 2002, 02:46 PM
here's a modifyied version of the previous swf i made, only i'll need to give you all the fla since the code is in numerous places.
<a href=http://www.danalu.com/thoriphes/gravity.swf>swf</a>
<a href=http://www.danalu.com/thoriphes/gravity.fla>fla</a>

ilyaslamasse
January 27th, 2002, 03:21 PM
Thanks, but I kind of managed to do it after all.
Tell me, how come your animations look good and mone look like @#%$ ?
pom

suprabeener
January 27th, 2002, 03:32 PM
cool...

the count was to stop the ball from vibrating perpetually at the end of it's bounces, kind of a hack solution.

eyez, cool book, but $$$. geez.

thoriphes
January 27th, 2002, 05:00 PM
i also forgot to mention, to get a clean, smooth looking animation, i recommend raising the movie's FPS to something like 50 (which i use all the time). remember, an onClipEvent(enterFrame) is just like an animation on the timeline.

kirupa
January 28th, 2002, 07:15 PM
This is really awesome! I have never known how to use gravity, and I gave up on it a few months ago.

Cheers,
Kirupa

Phil Jayhan
January 28th, 2002, 11:28 PM
This is so way alot supercool! I am studying the script and thank you for it Thoriphes. So cool.

pj
:cool:

Phil Jayhan
January 29th, 2002, 01:02 AM
Thoriphes,
This is so phun. I emulated what you did in your movie by recreating it. Since I am not a man of action (yet) I had to paste and copy your script. But it didn't werk right until I reread your post about the FPS. And it works! Looks just like yours. Mind you this just shows I have a fundemental understanding of how flash works and am good enough to recreate a masters scripts as long as I have the scripts. (I know, not saying much) But I am learning.

Q: What are some good tutorials I can learn these basic principles; And remember, give me ones that won't frustrate the hell out of me, something even a flashhopper can understand.

Q; Can people that aren't good @ math learn this just the same or is that a prereq?

pj
:cool:

eyezberg
January 29th, 2002, 05:09 AM
Peolpe yes, you No :)
(but just coz you're too tired by the time i'm posting this..)
If you manage to get a look at one of those "Masters of Flash" or whatever they're called books (still and always by friends of ED), you'll see page-long scripts, terrifying!!

thoriphes
January 29th, 2002, 10:27 AM
you don't necessarily need to be good in math in order to do this stuff. you just need to be able to think logically. i first approached emulating gravity by bouncing a ball. you'd be surprised what i did...
i converted the dimensions in flash all to the metric system (centimeters) just to use 9.8m/s^2, that didn't work too well.
now this was all just to bounce the @#%$ ball. the problem with flash is that math isn't everything. for example, with my script, you don't see 9.8m/s^2 or 4.somthing ft/sec anywhere in my script. this is how i came to that script:
i knew that with gravity, a falling object doesn't fall the same distance down per second. the distance they fall per second increases by a certain degree. when i got that code to work, i went on to working on the bouncing script. i knew that when a ball bounced, depending on it's "bounciness" (forget the term), it'll only bounce back up, but not all the way up from where it was dropped. also, gravity has a negative effect going up as well, the increments the ball rises decreases because of gravity. so the distance the ball bounces up decreases everytime.

finally, i added potential energy to the picture. if you don't know what that is, this is the one line of script that uses it:
vx = (x-oldx)*10; (for only the x).

potential energy well...is like how hard you throw a ball. the harder you throw it, the more potential energy it has, thus it goes farther. look up the word "potential" and you'll understand this a little better. anyway, study the script and try and understand what i just said, and it'll all come to you, regardless on your ability in math.

ilyaslamasse
January 29th, 2002, 02:52 PM
Are you good at physics, Phil, if you're not good at maths ? Cause there's a whole bunch of physics equations behind that "intuitive" approach Thoriphe gave you. I'm not sure you wanna hear it.

pom

Phil Jayhan
January 29th, 2002, 05:26 PM
Senior Lamasse, Thoriphes (is that a name of an Asian God) :D

I will study that script and learn all I can from it. It's all kind of intimidating. I always kind of thought the word potential had something to do with a female type human units looks and never realized it had other meanings, but I am confident now it does. But I'll tear it apart and play with it, I already changed numbers to see what would happen. Kind of cool. And read these posts till I gain new insights.

And as phar as the PHysics thing, Mr. Lamasse, well, I thought it had the same meaning as potential. I suck at PHysics. I suck at Math. And until I learn more, I suck a phlash. At least when I see other peoples werk. I pheel great until, well, I do that click thang, like Donnas site. I didn't even put my site in her e-mail, doing kirupa a phavor so as not to scare her away. But I slowly getting better.

pj
0]

ilyaslamasse
January 29th, 2002, 06:37 PM
Everything you ever wanted to know about gravitation in Flash but were afraid to ask 0]
pom
OK, the background was supposed to be grey, so that we actually see the WHITE animation. Toobad, I guess.

Phil Jayhan
January 30th, 2002, 02:52 AM
Thanks Ilyas,
Believe it or not, that helped a little. I know I will not grasp large concepts all at once, but everything here has helped from studying and reproducing Thoriphes movie from his script to your little personal tute, which, although I couldn't see the animation was still very instructional. Howbeit, it did need a back button so I could read and reread but it was good and Kirupa should give you extra credit or something.

pj

ilyaslamasse
January 30th, 2002, 10:26 AM
*** Tear perling on wy red cheek...
pom, supporting your veto of emoticons.

Th3Cleaner
January 30th, 2002, 12:21 PM
This thread is exsactly why this board is #1 in my book !

you guys rock !