ForumsProgramming ForumHow to make a perfect hitTest in as2?

33 14338
Oseb
offline
Oseb
29 posts
20

Hi everybody!
Im working on a game, but when i make a hitTest its not work perfectly (stops before reach the object). I use this code:

onClipEvent (enterFrame) {
if (_root.MC1.hitTest(this)) {
_root.MC1._y-= 5;
}
}

Any idea how to make it? Please explain it please.

  • 33 Replies
Oseb
offline
Oseb
29 posts
20

I have two more questions.
1) how to make moving wall, i mean my main character hits the moving object. Here i think those coordinates dont work.

2) arobegamr you said this code.
if(this._y>200){
this._y=200
}
But this code makes that my charecter stops at y=200 but i want that my character stops when Y=200 X>100 X<200? I tryed it many ways and i couldnt find the good code.

ReillyGregorio
offline
ReillyGregorio
1 posts
65

is there anyway i can do this without on clip event i am using
function onEnterFrame(){

}
the hit test i use is this but it makes the player bounce and i just want him to stop and still be able to jump
if (floor.hitTest(char._x, char._y, true )) {
yspeed --;
}

mightybob
offline
mightybob
363 posts
1,060

Why not just

If(still_object.hitTest(moving_object2.x, moving_object2.y, true))
{
//your code
}

Of course for this to work you need registration point where it's gonna hit.
Be sure to add in _root.'s or a movieClip var.

Showing 31-33 of 33