HOME | DD

NaamHier — gravity prototype

Published: 2011-01-31 18:48:08 +0000 UTC; Views: 478; Favourites: 1; Downloads: 7
Redirect to original
Description i am trying to make a new game with gravity in it and becous it has multiple floors and one movieclip with them in it would mess it up i made this.

heres the code for who wants it.

onClipEvent (load) {
objectarray = [_root.object1, _root.object2, _root.object3]; // a array with all objects that should stop whatever you want to put gravity on
}
onClipEvent (enterFrame) {
i = 0;//reset i
while (i<91) { // while() function to loop the hittests
if (this.hitTest(objectarray[i])) { // hittests the part of the array at i
this._rotation+=5 // this is if the movie clip needs to do somthing special if it hits the ground, if you leave this out it just stops falling
break; // break the while function so that flash wil start chekking for hittests at the first part of the array again
} else {
i += 1; // raise i to chek the next part in the array
}
if (i == 90) { // if evry part is cheked the gravity kicks in (the arrray is a lot lower then 90 so when it gets there it means the movie clip doesnt hit anyting)
this._y += 5;
}
}
}



if you want it to acelerate you will need to work with a few more variables but this is so you know how to make flash chek all floor movieclips befor doing somting
Related content
Comments: 0