Character doesn't jump

  • Hello,
    Here's the code I use in the update loop in my player's class, the player is supposed to play in a game which behaves as a platform.

    	 if (left && right) {left = false; right = false; }
    	 else if (right) {velocity.x = maxVelocity.x*4; facing = FlxObject.RIGHT;'right');  }
    	 else if (left) {velocity.x = - maxVelocity.x*4; facing = FlxObject.LEFT;'left');  }
    	 else if (up && isTouching(FlxObject.DOWN)) {velocity.y = 100;}
    	 else {velocity.y = 150; velocity.x = 0; }

    The character moves left and right, but doesn't jump.
    What could be the problem?

  • administrators

    It looks like in the if (up)-branch, you're setting the player's y velocity to a positive value (so just gravity basically), but for jumping, you want a negative one:

    velocity.y = -100;

  • Thanks :)

Log in to reply