Help with jumping script

  • Im trying to make a mario type game and can't seem to get the jumping to work the way I want. I want the character to jump of course, but I want the jump to be key sensitive. I want the character to jump higher when the button is held longer. The code I have works, until you press the key twice while the character is in mid jump. The character will fall down further then what it should fall. I know the problem is with my countHeight variable which adds to the height of the jump when the key is held down. Can anybody help me come up with a better script that is fool proof?

    onClipEvent(load)
    {
    var count = 0;
    var countHeight = 0;
    var jump = false;
    var jumpLevel = 2;
    var jumpY = -9;
    }


    onClipEvent(enterFrame)
    {
    if(key.isDown(Key.CONTROL))
    {
    if(countHeight != 9)
    countHeight ++;
    if(jump != true)
    jump = true;
    }

    if(jump)
    {
    count ++;
    this._y += jumpY;
    if(count == jumpLevel+countHeight)
    {
    jumpY = -jumpY;
    }
    if(count == 2*(jumpLevel+countHeight))
    {
    jumpY = -jumpY;
    count = 0;
    jump = false;
    }
    }
    else
    countHeight = 0;
    }


  • onClipEvent(load)
    {
    jump = 0
    jumping = false
    floor = 300
    }
    onClipEvent(enterFrame)
    {
    keycontrol = Key.isDown(Key.CONTROL)
    if(keycontrol and jumping == false)
    {
    jump = -20
    jumping = true
    }
    else if(keycontrol and jump > 0)
    {
    jump -= 2
    }
    if(jumping == true)
    {
    jump += 4
    _y += jump
    if(_y > floor)
    {
    _y = floor
    jumping = false
    }
    }
    }

    this should work... until you start adding things like platforms.


  • i cant help u...







  • #If you have any other info about this subject , Please add it free.#
    Your name:
    E-mail:
    Telphone:

    Your comments:


    If you have any other info about Help with jumping script , Please add it free.

    8 January 2009 | cameltoepants.com | edit