-
adding gravity?
how do you add gravity to a movie clip?
-
All 1s and 0s
Oh boy that's a question and a half.
I'm hoping to write a tutorial on this at some point. Until then, look here (or wait for someone else to reply!).
"If I have seen further, it is by standing on the shoulders of giants." - Sir Isaac Newton
-
its really quite simple if you don't want anything fancy; flash has two axis, the y and x axis. but the axis is flipped, so the left top corner is 0,0. If you want gravity, then u just have to change the movieclip's position(y) by doing this:
...
_root.object_mc._y++;
...
if you put that on enterFrame then it will run constantly at every frame so the object will fall like you wanted it. It won't stop falling though, but i think you can figure out how to take care of that, just put in a conditional statement.
-
Here's an example. I drew a ball, made it into a movieclip and added this code.
Code:
onClipEvent (load) {
yspeed = 0;
gravity = .3;
}
onClipEvent (enterFrame) {
this._y += yspeed;
yspeed = yspeed + gravity;
if (this._y >= 400) {
this._y = 400;
yspeed *= -.7;
}
}
This is just a basic example.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|