# Platformer physics - hitTests + Gravity

**URL:** https://forum.kirupa.com/t/platformer-physics-hittests-gravity/72618
**Category:** programming
**Created:** [December 7, 2004, 5:55pm UTC](https://forum.kirupa.com/t/platformer-physics-hittests-gravity/72618 "2004-12-07T17:55:27Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Sammo](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/sammo/32/779_2.png) [@Sammo](https://forum.kirupa.com/u/Sammo)
#### Post date: [December 7, 2004, 5:55pm UTC](https://forum.kirupa.com/t/platformer-physics-hittests-gravity/72618/1 "2004-12-07T17:55:27Z")

</div>

Hey, I figured this would be a popular subject, so i **did** search the forums, but didn’t find anything relevent to my point. Whether I can search correctly, I’m sure i’ll be corrected on 😛

Anyway, I’m a novice at AS, but I want to create a platformer (don’t worry! I’m not going to ask you lot to do it!), just for fun + practice. It’ll be Mario-esque, just for the lack of creativity needed to create it. 😛  
I can handle all the controls and DuplicateMovieClip() etc. It’s the hitTest + gravity i’m worried about. Here is an example of my hitTests:

```auto

onClipEvent (load) {
	speed = 5;
}
onClipEvent (enterFrame) {
	if (Key.isDown(Key.LEFT)) {
		_x -= speed;
	}
	if (this.hitTest(_root.wall_left)) {
		_x += speed;
	}
	if (Key.isDown(Key.RIGHT)) {
		_x += speed;
	}
	if (this.hitTest(_root.wall_right)) {
		_x -= speed;
	}
	if (Key.isDown(Key.UP)) {
		_y -= speed;
	}
	if (this.hitTest(_root.wall_up)) {
		_y += speed;
	}
	if (Key.isDown(Key.DOWN)) {
		_y += speed;
	}
	if (this.hitTest(_root.wall_down)) {
		_y -= speed;
	}
}
/*wall_up,down,left,right are instance names of a 
movieclip called wall which is on the stage 4 times. 
Boundries, wall_up at the top of the stage, etc.*/

```

Which is all very simple, but it works, so it’s been fine for me.

When I introduce gravity (which I need help with, but will get onto in a moment), The character won’t fall with an even pace, so i wont be able to counter the speed as I have done in the code above.

Is there a more technical way of using hitTests to stop a character?

And how would I implement gravity (I have searched and read the forums, and read Poms tutorial but im still not sure) into a game, such as a 2D platformer?
