Hittest, Ground

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?

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.

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.

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

 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;
  }
 }
} 

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?

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.

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

Those are only used for the sides, Maybe try:


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


nope, still doesn’t stop him.

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

no, I don’ think so. I checked

It worked fine for me.

Thx, for the code.

any time :D.

peace

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

oh,sure

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


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]
}

oh,ok thanks alot.

No problem ^_^.