Game Development Reference
In-Depth Information
// Use the jumpDirection variable to specify if the player
// should be jumping left, right, or vertical
float jumpDirection = 0.0f;
if(currentState ==
PlayerStateController.playerStates.left)
jumpDirection = -1.0f;
else if(currentState ==
PlayerStateController.playerStates.right)
jumpDirection = 1.0f;
else
jumpDirection = 0.0f;
// Apply the actual jump force
rigidbody2D.AddForce(new Vector2(jumpDirection *
playerJumpForceHorizontal, playerJumpForceVertical));
playerHasLanded = false;
PlayerStateController.stateDelayTimer[
(int)PlayerStateController.playerStates.jump] = 0f;
}
break;
At the beginning of PlayerStateListener , add the following variable:
private bool playerHasLanded = true;
Under the switch condition currentState , in the checkForValidStatePair
method, add the following code:
case PlayerStateController.playerStates.jump:
// The only state that can take over from Jump is landing
//or kill.
if(newState == PlayerStateController.playerStates.landing
|| newState == PlayerStateController.playerStates.kill
|| newState == PlayerStateController.playerStates.firingWeapon
)
returnVal = true;
else
returnVal = false;
break;
In the onStateCycle method, you don't need any special code. However, to keep
things clear, make sure that it has a place for jumping using the following jump case:
case PlayerStateController.playerStates.jump:
break;
 
Search WWH ::




Custom Search