A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: adding gravity?

  1. #1
    Junior Member
    Join Date
    Aug 2006
    Posts
    4

    adding gravity?

    how do you add gravity to a movie clip?

  2. #2
    All 1s and 0s dmonkey's Avatar
    Join Date
    Nov 2005
    Location
    Leeds, UK
    Posts
    606
    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

  3. #3
    Junior Member
    Join Date
    Aug 2006
    Posts
    3
    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.

  4. #4
    Junior Member
    Join Date
    Aug 2006
    Posts
    8
    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center