A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: jumping

  1. #1
    Member
    Join Date
    Sep 2004
    Location
    Qc
    Posts
    53

    jumping

    how do i make it so that a movieclip (man) goes up about an inch, slows down and keeps going down until it collides (_root.man.legs.feet) and then stops?

  2. #2
    Senior Member jbum's Avatar
    Join Date
    Feb 2004
    Location
    Los Angeles
    Posts
    2,920
    You want to use a velocity variable to track the motion. Kind of like this (vy is my velocity variable).

    A gravity constant is used to control the rate of falling.

    By tweaking both the initial force of the jump (-10 in the example below), and gravity constant (.5 in the example below), you should be able to arrive at something suitable.

    code:


    kGroundY = 300; // vertical coordinate of ground plane

    kGravity = 0.5; // gravity - affects the height of jump and speed of falling
    // adjust to taste

    MovieClip.prototype.startJump = function(initialForce)
    {
    this.vy = initialForce;
    this.onEnterFrame = function()
    {

    this.vy += kGravity;

    if (this._y + this.vy > kGroundY)
    {
    this._y = kGroundY;
    this.vx = 0;
    delete this.onEnterFrame;
    }
    else
    this._y += this.vy;
    }
    }

    man.startJump(-10);


  3. #3
    Member
    Join Date
    Sep 2004
    Location
    Qc
    Posts
    53
    where exactly do i put this?

  4. #4
    leight.com.au leight's Avatar
    Join Date
    Sep 2002
    Location
    australia
    Posts
    1,437
    There are many ways to make a character jump. I'm guessing you're wanting to create a type of platformer? Anyway, to find out heaps of different ways to jump, check out the knowledge base at the very top of the games forum

    - Leighton

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