Game Development Community

Problem with Jump function (Platformer tutorial)

by Eric Nelson · in Game Design and Creative Issues · 03/01/2012 (10:47 pm) · 0 replies

Ok, so I've been looking at the documentation, specifically the platforming tutorial, for ideas for a class project. I'm trying to implement basic functions into the engine to try and get the functionality I want working, but running into a problem with my character jumping. In the tutorial, it runs into the problem of the character being able to jump while in the air which it "fixes" with the following function:
function playerJump()
{
	%yVelocity = $pGuy.getLinearVelocityY();
	%xVelocity = $pGuy.getLinearVelocityX();

	$pGuy.setLinearVelocityY(100);
	$pGuy.setLinearVelocityX(0);

  	%collision = $pGuy.castCollision(0.005);
    
	if(!(%collision $= ""))
	{
		$pGuy.setLinearVelocityY(-225);
	}
	else
	{
		$pGuy.setLinearVelocityY(%yVelocity);
	}

	$pGuy.setLinearVelocityX(%xVelocity);
}

However, when I implement the same code into my file the player is unable to jump. When just using the original code he jumps fine. I'm not sure what is wrong since the tutorial itself says that everything is working now when it isn't.

About the author