(I) IMPORTANT: Understanding this section is vital to using Platformer PRO.
Platformer PRO includes a flexible movement system which allows for new movements to be easily added to an existing character.
Each movement added to the Character GameObject OR any child GameObject of the Character GameObject is added to an ordered list of movements called the movements list. The order that Movements appear in the GameObjects is the order in which they are added to the list. Those highest in the list of Components in the GameObjects are added to the list first and have a higher priority than Movements added later.
The character requires at the very least two default movements. One for when in the air and one for when on the ground.
The last GroundMovement in the movement list is considered to be the DefaultGroundMovement. The last AirMovement in the movement list is considered to be the DefaultAirMovement.
Determining the Current Movement
Each frame the character works out which movement should be controlling the character at this point in time. If the character is on the ground then they will probably be controlled by a GroundMovement, if they are climbing a ladder then they will probably be controlled by a LadderMovement, and so on.
It is important to understand how this decision is made:
Step 1. At the start of each frame the activeMovement, that is the movement that was in control last frame is asked if it ForceMaintainControl(). The activeMovement is always given this option to maintain control (see Defining Custom Movements for more information).
Step 2. If the activeMovement does not want control then each Movement in the movement list is then queried to see if it wants control. The nature of the method depends on the movement type (for example an AirMovement will be asked if it WantsJump() or WantsAirControl(), a GroundMovement will be asked if it WantsGroundControl()).
Step3. If none of the movements wants control then either the DefaultAirMovement is given control if the character is in the air or the DefaultGroundMovement is given control if the character is not in the air.
Transitioning Movement Control
Once the movement for the current frame is determined the character will check to see if the new movement is different to the active movement. If they are not different nothing special happens and the activeMovement continues to control the character. If they are different the character transitions the movement control over to the new movement:
Step 1. The activeMovement is informed that it is LosingControl(). This enables the movement to clear any data and reset the state back ready to gain control at a later time.
Step 2. The new movement is told that it is GainingControl(). This enables the movement to do any initialisation required such as transforming the current velocity in to a measure that is understood by this controller (see Understanding VelocityType).
Step 3. The new movement becomes the active movement and takes over control of the character.
Imagine a character with the following movements in this order:
1. GroundMovement - Crouch
2. AirMovement - Digital (DefaultAirMovement)
3. GroundMovement - Digital (DefaultGroundMovement)
If the player is standing on the ground no movement wants movement control and thus control falls through to 3 because it is the default.
If the player then presses the jump button the AirMovement (2) will return true to WantsJump() and thus control will be passed to 2.
If the player presses down while in the air nothing happens the GourndMovement (1) will not want control because the character isn't grounded. The control will default back to the DefaultAirMovement (2).
Once the player continues to hold down when the character lands on the ground control will now pass to the Crouch movement (3) because it WantsGroundControl() if the character is grounded and the player is pressing down. The character will crouch.
Now consider what happens if we switch the order of 1 and 3.
1. GroundMovement - Digital
2. AirMovement - Digital (DefaultAirMovement)
3. GroundMovement - Crouch (DefaultGroundMovement)
If the player is standing on the ground no movement wants movement control and thus control falls through to 3 because it is the default. The character will crouch instead of idling!
Jumping will still work as normal but the character will never be able to stand.
Important: If you are using a prefab for your Character you MUST apply the changes to the prefab for the component order to be applied. Unity has a bug where the prefabs component order overrides the component order of the GameObject (unlike any other time when the GameObjects settings override the Prefabs).