# Walking on a slope while using real gravity

**URL:** https://forum.kirupa.com/t/walking-on-a-slope-while-using-real-gravity/325854
**Category:** programming
**Created:** [November 8, 2011, 5:57pm UTC](https://forum.kirupa.com/t/walking-on-a-slope-while-using-real-gravity/325854 "2011-11-08T17:57:22Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![scarce](https://avatars.discourse-cdn.com/v4/letter/s/65b543/32.png) [@scarce](https://forum.kirupa.com/u/scarce)
#### Post date: [November 8, 2011, 5:57pm UTC](https://forum.kirupa.com/t/walking-on-a-slope-while-using-real-gravity/325854/1 "2011-11-08T17:57:22Z")

</div>

ok, well I scratched my old physics on the game and decided to go based on real physics…I used an actualy gravity algorithum based on mass, distance, yada yada…I’m still having a problem with walking on a slope, making the character go up and down basically.

[as]  
function charDist(event:Event):void  
{  
gPull = gravity \* eraserMass / dist \* dist;  
getDist(eraserMan.x, eraserMan.y, theGround.x, theGround.y);  
trace(touchDown);

```
		}
		function getDist(x1:Number, y1:Number, x2:Number, y2:Number):Number
		{
			dx = x1 - x2;
			dy = y1 - y2;
			dist = Math.sqrt(dx * dx + dy * dy);
			return dist;
		}
		function gravity(event:Event):void
		{
			velocity -= gPull;

			while (theGround.hitTestPoint(eraserMan.x,eraserMan.y,true))
			{

				eraserMan.y += velocity;
				

			}

			while (! theGround.hitTestPoint(eraserMan.x,eraserMan.y,true))
			{
				eraserMan.y -= velocity;
				

			}

		}

```

[/as]

the gravity function is where the issue is…the character falls faster and slower based on weight and distance…thats all great. But once I hit the ground, he stays linear…help please 😃
