Gravity

Here’s the result. Any idea ?\rpom

hope this helps:\r<a href=http://www.danalu.com/thoriphes/gravity.swf>here</a>\rif you need to see the fla, then let me know, but all the script in the movie is seen on the swf anyway…

this site came up when i was looking for real equations:\rhttp://library.thinkquest.org/16600/\r\rit’s a great site.\r\ri 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.\r\r<EMBED src=“http://members.shaw.ca/rlinton/posts/gravity.swf” quality=high bgcolor=#FFFFFF WIDTH=300 HEIGHT=300 TYPE=“application/x-shockwave-flash”></EMBED>\r\rthe code on ball is:

<font color="#000070">\ronClipEvent(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>

Oh supra’, my scripting god, this might be one for you:\r\rwww.friendsofed.com/books…index.html\r\rseems to be new -and expensive- haven’t had a chance to get a look yet…

Thoriphe, thank you very much, your script is clear as holy water (as always).\rSupra, I don’t understand the utility of count. Very interesting link by the way.\rEyez, that book looks awesopme. If you ever buy it ($50 !!, @#%$ !!), you know where to find me…\r\rpom

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.\rHere’s the lowdown : mass * acceleration = sum of the forces (here : weight only)\rSo acceleration = gravity constant G\rand velocity = G*Time elapsed + original speed\rAnd you get this :

Where’s the replay?\rBy the time the page is loaded, the anim is over :slight_smile:

Couldn’t do it… Dammit !! You got me, Austin Powers !\rAny idea how to reset a timer ?\rAustin\rOk got round it :

Why doesn’t it work when you edit and add the “custom signature” ?\rpom\rDammit !!!

I hate it !!!\rBy the way, the ball seems to float a little bit because I set the gravity to 1 instead of 10.\rpom\r\rPS : 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 ?

I’m having fun, or should I say… phun ? 0] Now you can drad the ball and give it the speed you want.\rpom

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.\r<a href=http://www.danalu.com/thoriphes/gravity.swf>swf</a>\r<a href=http://www.danalu.com/thoriphes/gravity.fla>fla</a>

Thanks, but I kind of managed to do it after all.\rTell me, how come your animations look good and mone look like @#%$ ?\rpom

cool…\r\rthe count was to stop the ball from vibrating perpetually at the end of it’s bounces, kind of a hack solution.\r\reyez, cool book, but $$$. geez.

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.

This is really awesome! I have never known how to use gravity, and I gave up on it a few months ago.\r\rCheers,\rKirupa

This is so way alot supercool! I am studying the script and thank you for it Thoriphes. So cool. \r\rpj\r:cool:

Thoriphes,\r 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.\r\r 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.\r\r Q; Can people that aren’t good @ math learn this just the same or is that a prereq?\r\rpj\r:cool:

Peolpe yes, you No :slight_smile:
(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!!

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.