Be a Supporter!

Plattformer ground hitTest?

  • 362 Views
  • 8 Replies
New Topic Respond to this Topic
Havegum
Havegum
  • Member since: Oct. 20, 2008
  • Offline.
Forum Stats
Supporter
Level 24
Melancholy
Plattformer ground hitTest? 2009-06-17 19:25:40 Reply

Say i have a character hero_MC, and i want him to stop when he hits ground_mc.
The ground has several slopes, sircles and stuff. How do i script this?

Plattformer ground hitTest?


BBS Signature
Havegum
Havegum
  • Member since: Oct. 20, 2008
  • Offline.
Forum Stats
Supporter
Level 24
Melancholy
Response to Plattformer ground hitTest? 2009-06-17 19:41:59 Reply

i really need help on this one guys... please help me!


BBS Signature
Riisk
Riisk
  • Member since: Jun. 10, 2009
  • Offline.
Forum Stats
Member
Level 03
Blank Slate
Response to Plattformer ground hitTest? 2009-06-17 19:48:03 Reply

Well if you havent allready coded the movement into your Player then your okay, you can use a tutorial.

But
If you have a problem like mine, well..

basicly, ive found a great movement script and all the collision scripts i can find dont work with it.

Check this tut out :

hope i helped.

Mattster
Mattster
  • Member since: Nov. 21, 2007
  • Offline.
Forum Stats
Member
Level 20
Game Developer
Response to Plattformer ground hitTest? 2009-06-17 19:49:05 Reply

I guess it varies on what script you are using.

You'll want something like this:

onClipEvent (enterFrame){
    if (this.hitTest(_root.Ground_MC)){
               trace ("hit");
     }
}

-Matt

Riisk
Riisk
  • Member since: Jun. 10, 2009
  • Offline.
Forum Stats
Member
Level 03
Blank Slate
Response to Plattformer ground hitTest? 2009-06-17 19:58:25 Reply

matt, that script doesnt work.

Makes the output box go mental with Hittests, even when im not moving at all.

But doesnt stop the player from passing through my walls.

And yes i did change the script to suit my instances.

atomoxic
atomoxic
  • Member since: Feb. 16, 2009
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
Response to Plattformer ground hitTest? 2009-06-17 20:04:35 Reply

It makes it output loads of "hits" because it dosent include the shapeflag. A regular hitTest just checks if the object is within the rectangle that can be drawn around the object whereas a shapeflag detects actual point to drawing collision.

Something such as this would be appropriate:

if (_root.Ground_MC.hitTest(this._x, this._y, true) {
         trace("hit"); // Do some function here to stop player passing through walls.
}

BBS Signature
Riisk
Riisk
  • Member since: Jun. 10, 2009
  • Offline.
Forum Stats
Member
Level 03
Blank Slate
Response to Plattformer ground hitTest? 2009-06-17 20:12:11 Reply

Here you go mate:

Put this after the final " } " in your script on the player:

onClipEvent(load){
radius = _width/2 - 1;
}
onClipEvent(enterFrame){
while(_root.Ground_mc.hitTest(_x, _y+radius, true)){
_y--;
}
while(_root.Ground_mc.hitTest(_x, _y-radius, true)){
_y++;
}
while(_root.Ground_mc.hitTest(_x-radius, _y, true)){
_x++;
}
while(_root.Ground_mc.hitTest(_x+radius, _y, true)){
_x--;
}
}

atomoxic
atomoxic
  • Member since: Feb. 16, 2009
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
Response to Plattformer ground hitTest? 2009-06-17 20:14:26 Reply

Dont forget that the x=0 and y=0 points need to be in the center of your movieclip otherwise the above code will not work as intended.


BBS Signature
Havegum
Havegum
  • Member since: Oct. 20, 2008
  • Offline.
Forum Stats
Supporter
Level 24
Melancholy
Response to Plattformer ground hitTest? 2009-06-17 20:25:06 Reply

YEESSS!!! THANK YOU SOOO MUUCH!!


BBS Signature