# Hittest, Ground

**URL:** https://forum.kirupa.com/t/hittest-ground/64314
**Category:** programming
**Created:** [September 15, 2004, 3:46am UTC](https://forum.kirupa.com/t/hittest-ground/64314 "2004-09-15T03:46:08Z")
**Posts on this page:** 18
**Page:** 1

<div class="post-metadata">

### Author: ![ckyfan](https://avatars.discourse-cdn.com/v4/letter/c/7993a0/32.png) [@ckyfan](https://forum.kirupa.com/u/ckyfan)
#### Post date: [September 15, 2004, 3:46am UTC](https://forum.kirupa.com/t/hittest-ground/64314/1 "2004-09-15T03:46:08Z")

</div>

I was looking at the mario topic and made my guy jump, but when he jumps he keeps falling and doesnt stop. So how would I make him stop falling for when he hits the ground?

---

<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: [September 15, 2004, 4:04am UTC](https://forum.kirupa.com/t/hittest-ground/64314/2 "2004-09-15T04:04:12Z")

</div>

depending on how you build you world is how you can make him stop…

If you do tiles, you can do tile testing… If you do some other world type… You’ll have to use hitTest or another form of collission detection… that will instantly stop your character.

---

<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: [September 15, 2004, 4:25am UTC](https://forum.kirupa.com/t/hittest-ground/64314/3 "2004-09-15T04:25:07Z")

</div>

Well, I’m not doing tiles. Im not sure actually I just pasted ground on to the stage. So how would I script it? For me to stop jumping, and hittest.

---

<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: [September 15, 2004, 4:30am UTC](https://forum.kirupa.com/t/hittest-ground/64314/4 "2004-09-15T04:30:57Z")

</div>

Make the ground call it “limits” give it instance name "limits"  
put this action script on your character

```php
 onClipEvent (enterFrame) {
 if (started) {
  if (_root.limits.hitTest(_x+x+b.xmin+5, _y+y+b.ymin+5, true)) {
   this._x += xspeed;
  }
  if (_root.limits.hitTest(_x+x+b.xmax-5, _y+y+b.ymin+5, true)) {
   this._x -= xspeed;
  }
 }
} 

```

---

<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: [September 15, 2004, 5:27am UTC](https://forum.kirupa.com/t/hittest-ground/64314/5 "2004-09-15T05:27:31Z")

</div>

hmmm. . . did what you said but the ground didn’t stop him from falling.  
I named the ground limits, instance and all . . .what is the ground to be converted to?  
a movieclip?  
I added the script. I’m not sure whats wrong?

---

<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: [September 15, 2004, 6:55am UTC](https://forum.kirupa.com/t/hittest-ground/64314/6 "2004-09-15T06:55:25Z")

</div>

The script needs to go in your character instance, your ground instance needs to be named “limits”, and you need to have some extra variables according to FlashNewb’s script. I don’t understand them all, so he should explain them.

For future reference and more help on your game, please browse through the current tutorials on this topic and use the search function to search through the topic currently posted. Then if your question is not answered 5 time already (sarcasm there) then go ahead and post.

---

<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: [September 15, 2004, 8:38am UTC](https://forum.kirupa.com/t/hittest-ground/64314/7 "2004-09-15T08:38:42Z")

</div>

There should be a noob game/ai forum and advanced, there has got to be about a million questions all asking the same thing. Though i guess this would be fixed if more people were willing to share their source for games, but this won’t happen

---

<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: [September 15, 2004, 1:50pm UTC](https://forum.kirupa.com/t/hittest-ground/64314/8 "2004-09-15T13:50:45Z")

</div>

> [@FlashNewbi3](#):
>
> Make the ground call it “limits” give it instance name “limits”  
> put this action script on your character
> 
> ```php
> onClipEvent (enterFrame) {
> if (started) {
> if (_root.limits.hitTest(_x+x+b.xmin+5, _y+y+b.ymin+5, true)) {
> this._x += xspeed;
> }
> if (_root.limits.hitTest(_x+x+b.xmax-5, _y+y+b.ymin+5, true)) {
> this._x -= xspeed;
> }
> }
> } 
> 
> ```

Those are only used for the sides, Maybe try:

```php

onClipEvent (enterFrame) {
	 if (_root.limits.hitTest(this._x, this._y+15, true)) {
		 this._y -= gravity;
	 }
}

```

---

<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: [September 15, 2004, 2:36pm UTC](https://forum.kirupa.com/t/hittest-ground/64314/9 "2004-09-15T14:36:29Z")

</div>

nope, still doesn’t stop him.

---

<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: [September 15, 2004, 2:54pm UTC](https://forum.kirupa.com/t/hittest-ground/64314/10 "2004-09-15T14:54:33Z")

</div>

Hmmm, mabe its where you are placing the code? Or mabe the names of the mcs?

---

<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: [September 16, 2004, 2:32am UTC](https://forum.kirupa.com/t/hittest-ground/64314/11 "2004-09-16T02:32:55Z")

</div>

no, I don’ think so. I checked

---

<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: [September 16, 2004, 2:48am UTC](https://forum.kirupa.com/t/hittest-ground/64314/12 "2004-09-16T02:48:18Z")

</div>

It worked fine for me.

Thx, for the code.

---

<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: [September 16, 2004, 3:34am UTC](https://forum.kirupa.com/t/hittest-ground/64314/13 "2004-09-16T03:34:03Z")

</div>

> [@Commandersa](#):
>
> It worked fine for me.
> 
> Thx, for the code.

any time :D.

peace

---

<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: [September 16, 2004, 3:42am UTC](https://forum.kirupa.com/t/hittest-ground/64314/14 "2004-09-16T03:42:54Z")

</div>

> [@ckyfan](#):
>
> no, I don’ think so. I checked

Mabe if I took a look at it I could figure it out, would you mind posting the fla?

---

<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: [September 16, 2004, 4:16am UTC](https://forum.kirupa.com/t/hittest-ground/64314/15 "2004-09-16T04:16:27Z")

</div>

oh,sure

---

<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: [September 16, 2004, 1:02pm UTC](https://forum.kirupa.com/t/hittest-ground/64314/16 "2004-09-16T13:02:24Z")

</div>

> [@ckyfan](#):
>
> oh,sure

AHA! I found the problem :). Ok, you have your jumping code, right? Well, now we put the ground code after it. Example:

```auto

onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)) {
this.gotoAndStop(2);
this._xscale = 100;
this._x += speed;
} else if (Key.isDown(Key.LEFT)) {
this.gotoAndStop(2);
this._xscale = -100;
this._x -= speed;
} else {
this.gotoAndStop(1);
}
if (Key.isDown(Key.UP)) {
this.gotoAndStop(3);
move = false;
vel_y = 10;
jumping = true;
}
if (jumping == true) {
vel_y -= 1;
if (vel_y<=-10) {
vel_y = -10;
}
this._y -= vel_y;
}
[color=red]if (_root.limits.hitTest(this._x, this._y+15, true)) {
jumping = false;
}[/color]
}

```

---

<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: [September 16, 2004, 2:06pm UTC](https://forum.kirupa.com/t/hittest-ground/64314/17 "2004-09-16T14:06:38Z")

</div>

oh,ok thanks alot.

---

<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: [September 16, 2004, 5:00pm UTC](https://forum.kirupa.com/t/hittest-ground/64314/18 "2004-09-16T17:00:24Z")

</div>

No problem ^\_^.
