# Gravity problem

**URL:** <https://forum.kirupa.com/t/gravity-problem/312994>\
**Category:** Uncategorized\
**Created:** [August 17, 2010, 8:04pm UTC](https://forum.kirupa.com/t/gravity-problem/312994 "2010-08-17T20:04:54Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![DAINO](https://avatars.discourse-cdn.com/v4/letter/d/2acd7d/32.png) [@DAINO](https://forum.kirupa.com/u/DAINO)\
**Post date:** [August 17, 2010, 8:04pm UTC](https://forum.kirupa.com/t/gravity-problem/312994/1 "2010-08-17T20:04:54Z")

</div>

Hello,

I am building a platform game.  
There is a problem. I have two MovieClip, one of the player, and one of the enemy. On both of them works gravity. I use attachMovie to attach them to the stage.  
my code is:

```auto
var grav:Number = 0;
var gravity:Number = 2;

enemySpawn = function(numEnemies){
	for(i=1;i<=numEnemies;i++){
		attachMovie("enemy", "enemy"+i, i);
		enemy2._x = 200;
		_root["enemy"+i].onEnterFrame = function(){
			this._y += grav;
			grav += gravity;
			while(ground.hitTest(this._x,this._y,true)){
				this._y -= gravity;
				grav = 0;
			}
		}
	}
}
enemySpawn(2);

```

Fla file is attached.

Thank you to the all those who helpful!!!
