# Center of gravity

**URL:** https://forum.kirupa.com/t/center-of-gravity/276155
**Category:** flash
**Created:** [November 23, 2008, 10:48pm UTC](https://forum.kirupa.com/t/center-of-gravity/276155 "2008-11-23T22:48:25Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Beeh](https://avatars.discourse-cdn.com/v4/letter/b/8491ac/32.png) [@Beeh](https://forum.kirupa.com/u/Beeh)
#### Post date: [November 23, 2008, 10:48pm UTC](https://forum.kirupa.com/t/center-of-gravity/276155/1 "2008-11-23T22:48:25Z")

</div>

I’ve searched for a long time for a center of gravity code, to see what I’ve been doing wrong. I can’t find one **at all**. And the one that I do have right now, it _just makes it go continuessly somehow_. (italcized because that’s one of the main problems)  
There’s also another problem, _it sometimes bounces back_. Which the code isn’t telling it to at all. And it also sometimes _goes to the top or left of the screen_, something I don’t see why it happens.

grav is the movieclip it’s supposed to be attracted to.

Here’s the code so far, obviously it’s not done

```auto
	var xdist = Math.round(_root.grav._x - this._x); 
	var ydist = Math.round(_root.grav._y - this._y);
	var dfs = Math.round(Math.sqrt((xdist*xdist)+(ydist*ydist)));
	xspeed=(xspeed/1.1)+(gravity/dfs);
	yspeed=(yspeed/1.1)+(gravity/dfs);
	this._x+=xspeed/20
	this._y+=yspeed/20

```
