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;
}