Game Development Reference
In-Depth Information
Just like OnTriggerEnter , this will be called whenever the SceneryToggler object
leaves another object. We then check the tag, and if this was a platform, we toggle the
falling state of the player. Let's also add the falling state real quick:
• In PlayerStateListener , add the following switch case in onStateCycle :
case PlayerStateController.playerStates.falling:
break;
• In PlayerStateListener , add the following switch case in onStateChange :
case PlayerStateController.playerStates.falling:
break;
• In PlayerStateListener , inside the landing case in
checkForValidStatePair, add the following:
case playerStateController.playerStates.landing:
// The only state that can take over from landing is idle,
//left or right movement.
if(
newState == PlayerStateController.playerStates.left
|| newState == PlayerStateController.playerStates.right
|| newState == PlayerStateController.playerStates.idle
)
returnVal = true;
else
returnVal = false;
break;
Got a glitch?
Now, you may have noticed a small glitch if you are holding down your jump button.
The player can occasionally get stuck in the ground and then refuse to move or
jump. The reason for this is how physics are checked. When objects are moving fast,
often they will actually intersect another object before the collision detection occurs.
This happens so fast your eyes will rarely ever actually notice it—but to the game's
physics, it can mean the difference between working and... freezing in one place.
We're now going to improve the capabilities of the state system to address this.
 
Search WWH ::




Custom Search