# Gravitation simulation

**URL:** <https://forum.kirupa.com/t/gravitation-simulation/3428>\
**Category:** Uncategorized\
**Created:** [January 28, 2002, 7:58pm UTC](https://forum.kirupa.com/t/gravitation-simulation/3428 "2002-01-28T19:58:20Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 28, 2002, 7:58pm UTC](https://forum.kirupa.com/t/gravitation-simulation/3428/1 "2002-01-28T19:58:20Z")

</div>

[www.multimania.com/ilyasl…ation.html](http://www.multimania.com/ilyaslamasse/gravitation.html)\rHere’s something I came up with messing with Newton’s equations. Not perfect at all but it’s a start : I’ve got the force field, and I lack inertia a little bit.\r\rpom 0]

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 29, 2002, 4:47am UTC](https://forum.kirupa.com/t/gravitation-simulation/3428/2 "2002-01-29T04:47:16Z")

</div>

Pom,\r When you see me tomorrow, send me this Fla if you wouldn’t mind, so i can study it and learn from it would ya? Nice job, kind of cool. I caught the ball a bunch of time, just wanted to let you know…\r\r\rpj\r:cool:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 29, 2002, 8:07pm UTC](https://forum.kirupa.com/t/gravitation-simulation/3428/3 "2002-01-29T20:07:38Z")

</div>

Well, the fla is a physics nightmare, since it deals with stuff I learned a while ago. So if you don’t know anything about physics, you’ll just see a lot of figures with no meaning. Actually, I’ve come to the point that I messed with the figures so much that they lost their meaning.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 29, 2002, 8:25pm UTC](https://forum.kirupa.com/t/gravitation-simulation/3428/4 "2002-01-29T20:25:59Z")

</div>

that is excellent. i have a lot of trouble keeping the ball on the screen.\r\rhave you thought about building one of those games where you choose angle and velocity, and try to hit you opponent through a field of planets, astroids, whatever, which affect the projectile?\r\rseems like you’ve already done the hard part.\r\rnice.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 29, 2002, 8:45pm UTC](https://forum.kirupa.com/t/gravitation-simulation/3428/5 "2002-01-29T20:45:31Z")

</div>

I don’t know if you guys remember the game “Scorch Earth” ‘the mother of all games’. it was a game where you opperated a tank and you need to shoot your opponents before they shoots you. you had to choose angle and velocity, a very cool trajectory (sp?) game.\r\rIt had some great options like…\r1. changing the strength of gravity\r2. wrap around screen\r3. rubber walls\r4. how windy (a horizontal gravity in effect)\r\rI guess what I am now asking is can it be done with flash and some gravity scripting, and help from you guys.\r\rMatt

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 29, 2002, 9:21pm UTC](https://forum.kirupa.com/t/gravitation-simulation/3428/6 "2002-01-29T21:21:09Z")

</div>

Hey Supra, I’m very flattered by what you said. I kind of solved the escaping problem by adding one component in my acceleration formula, but it’s still very difficult to make it stay. Working on it hard !! Concerning your game, it sounds like a lot of trouble if your projectile hits one of the asteroids. As you can see, this makes the planet (it’s a planet by the way) go totally astray. I don’t know ?\rAnd Matt, you’ve just had the greatest idea of all times. My game was called gorillas, and it was running in dosshell. You were a monkey, and you had to send bananas on another monkey, and there were buildings to adver and stuff… Really cool. That’s a great project. I’d love it if you tried and made this, I’ll try on my side.\r\rpom\r\r[www.multimania.com/ilyasl…tion2.html](http://www.multimania.com/ilyaslamasse/gravitation2.html)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 29, 2002, 10:12pm UTC](https://forum.kirupa.com/t/gravitation-simulation/3428/7 "2002-01-29T22:12:35Z")

</div>

Sounds neat Pom. Can you show me the script for that asteroid thats a planet killer? Maybe I could use it fer my monster so he can spit out asteroids and kill Icerbergs monster, I have suped up Dans worm, turned him into a monster but he still has no teeth, well, actually only one, looks kinda like a dork.\r\rpj\r:cool:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 29, 2002, 10:31pm UTC](https://forum.kirupa.com/t/gravitation-simulation/3428/8 "2002-01-29T22:31:00Z")

</div>

OK, here’s a little explanation about it : (right click the link and save link as…)\r[www.multimania.com/ilyasl…ation2.fla](http://www.multimania.com/ilyaslamasse/gravitation2.fla)\rIn the first frame, I define my functions :\r\rMovieClip.prototype.distance = function (a,b,c,d)\rreturns the distance between 2 clips of coordinates (a,b) and (c,d)\r\rMovieClip.prototype.angle = function (a,b)\rThe distance between two points has two components : on the x axis (a) and on the y axis (b). Based on that, you can find the angle between the 2 MC with the Math.atan function except it’s defined on [-pi/2;pi/2]\r\rMovieClip.prototype.force = function (g,m1,m2)\rgives the force applied to a MC, depending on the gravitationnal constant g, and the masses of the 2 objects\rstrengh = g_m1_m2/(r_r) ;\rthat’s the gravitation\rstrenghx = (-strengh+1.4_v_v/r) \* Math.cos(beta) ;\rThat’s the projection of gravitation + centripetal force on x axis\rstrenghy = (strengh+1.4_v_v/r) \* Math.sin(beta) ;\rthe same on y axis\rIn frame two :\rthe red dot has the code :\r\ronClipEvent (enterFrame) {\rdistance (\_x,\_y,\_root.clip2.\_x,\_root.clip2.\_y) ; //between it and clip2\rangle(dx,dy) ; //find the angle\rforce (100,10,10) ; //get the force\rstartDrag ( this, true ); //you can move it\r}\rthe blue one gets :\ronClipEvent (load) { //get the coordinates of the MC to set up speed\rxold = \_x ;\ryold = \_y ;\r}\ronClipEvent (enterFrame) {\rxnew = \_x +5 ;\rynew = \_y -5 ;\rvelx = (xnew - xold) + 0.6_\_root.clip1.strenghx ; //speed at a given moment + strengh\rvely = (ynew - yold) + 0.6\*\_root.clip1.strenghy ;\rv = Math.sqrt(velx\*velx+vely+vely) ; //real speed\r\_x += velx ;//position\r\_y += vely ;\rxold = xnew ;\ryold = ynew ;\r}\r\rYouhou !!!\r\rpom\rWelcome… to the real world, neo.
