The Enchanted Cave 2
Delve into a strange cave with a seemingly endless supply of treasure, strategically choos
4.39 / 5.00 38,635 ViewsGhostbusters B.I.P.
COMPLETE edition of the interactive "choose next panel" comic
4.09 / 5.00 15,161 ViewsSay 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?
i really need help on this one guys... please help me!
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 :
Click to view.
hope i helped.
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
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.
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.
}
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--;
}
}
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.