# Gravity

**URL:** https://forum.kirupa.com/t/gravity/3421
**Category:** programming
**Created:** [January 26, 2002, 1:33pm UTC](https://forum.kirupa.com/t/gravity/3421 "2002-01-26T13:33:53Z")
**Posts on this page:** 20
**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 26, 2002, 1:33pm UTC](https://forum.kirupa.com/t/gravity/3421/1 "2002-01-26T13:33:53Z")

</div>

I have programmed gravity a I could (with collision detection to make the ball bounce), but I have several problems :\r - 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) ;\r - 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.\r\rAny ideas ???\r\rpom

---

<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 26, 2002, 5:42pm UTC](https://forum.kirupa.com/t/gravity/3421/2 "2002-01-26T17:42:53Z")

</div>

Gravity sucks, i want to FLY !!

---

<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 26, 2002, 5:55pm UTC](https://forum.kirupa.com/t/gravity/3421/3 "2002-01-26T17:55:20Z")

</div>

So That’s what I want : A flying SuperIlyas 0] that you can control, but there must be some gravity in it !!!\r\rpom

---

<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 27, 2002, 1:14am UTC](https://forum.kirupa.com/t/gravity/3421/4 "2002-01-27T01:14:26Z")

</div>

Here’s the result. Any idea ?\rpom

---

<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 27, 2002, 1:36am UTC](https://forum.kirupa.com/t/gravity/3421/5 "2002-01-27T01:36:41Z")

</div>

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…

---

<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 27, 2002, 7:54am UTC](https://forum.kirupa.com/t/gravity/3421/6 "2002-01-27T07:54:09Z")

</div>

this site came up when i was looking for real equations:\r[http://library.thinkquest.org/16600/](http://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](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:

```auto
<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>

```

---

<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 27, 2002, 9:50am UTC](https://forum.kirupa.com/t/gravity/3421/7 "2002-01-27T09:50:02Z")

</div>

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

---

<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 27, 2002, 11:00am UTC](https://forum.kirupa.com/t/gravity/3421/8 "2002-01-27T11:00:53Z")

</div>

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

---

<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 27, 2002, 12:33pm UTC](https://forum.kirupa.com/t/gravity/3421/9 "2002-01-27T12:33:01Z")

</div>

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 :

---

<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 27, 2002, 12:41pm UTC](https://forum.kirupa.com/t/gravity/3421/10 "2002-01-27T12:41:19Z")

</div>

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

---

<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 27, 2002, 12:53pm UTC](https://forum.kirupa.com/t/gravity/3421/11 "2002-01-27T12:53:29Z")

</div>

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

---

<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 27, 2002, 1:09pm UTC](https://forum.kirupa.com/t/gravity/3421/12 "2002-01-27T13:09:56Z")

</div>

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

---

<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 27, 2002, 1:13pm UTC](https://forum.kirupa.com/t/gravity/3421/13 "2002-01-27T13:13:27Z")

</div>

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 ?

---

<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 27, 2002, 4:26pm UTC](https://forum.kirupa.com/t/gravity/3421/14 "2002-01-27T16:26:52Z")

</div>

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

---

<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 27, 2002, 7:46pm UTC](https://forum.kirupa.com/t/gravity/3421/15 "2002-01-27T19:46:36Z")

</div>

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\>

---

<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 27, 2002, 8:21pm UTC](https://forum.kirupa.com/t/gravity/3421/16 "2002-01-27T20:21:30Z")

</div>

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

---

<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 27, 2002, 8:32pm UTC](https://forum.kirupa.com/t/gravity/3421/17 "2002-01-27T20:32:51Z")

</div>

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.

---

<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 27, 2002, 10:00pm UTC](https://forum.kirupa.com/t/gravity/3421/18 "2002-01-27T22:00:42Z")

</div>

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.

---

<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, 12:15am UTC](https://forum.kirupa.com/t/gravity/3421/19 "2002-01-29T00:15:24Z")

</div>

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

---

<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:28am UTC](https://forum.kirupa.com/t/gravity/3421/20 "2002-01-29T04:28:29Z")

</div>

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

[Next page](https://forum.kirupa.com/t/gravity/3421.md?page=2)
