This sample demonstrates the implementation of two Kinematic Character Controllers that use a rectangle shape for 2D platformer games. Also, the sample showcases some core mechanics commonly found in platformer games such as the Double Jump or Wall Jump.
This project can be used as a starting point for a product-ready 2D Platformer Game, but as each game has its own particular mechanics it may be necessary to modify or reimplement some of the systems.
Simple Kinematic Character Controller
This character controller is projected to be used in platformer games with a tiled level design. It also supports climbing slopes, but it can’t go down ramps smoothly.
Advanced Kinematic Character Controller
This character controller is projected to be used in games with complex level designs and curved terrain. Some features are only possible with this controller, such as grabbing on edges or smoothly running through the terrain. It implements a state machine and can be used in games with complex combat systems as each state has its own behavior.
NOTE: This controller uses 2 more raycasts than the simple KCC so it is more CPU intensive.
The project has been developed with:
- Unity 2020.3.40f1
- Quantum 2.1.1 Stable 1123
NOTE: This sample uses XY as a 2D plane. It is possible to set up this in
|2.1.7||Sep 21, 2023||Quantum 2D Platformer 2.1.7 Build 275|
- Character Mechanics:
- Double Jump
- Wall Jump
- Input Buffer
- Coyote Time
- Apex Time
- Movable Platforms
- Pushable Objects
- Two-Way Platforms
- Dropdown Menu to change levels and mechanics
- UI Toggle to enable and disable mechanics
- Online Matchmaking
Quantum Project Structure
CustomCharacterController2D folder has the scripts to control the character and all mechanics to be used in-game. The
PlatformEnvironment folder has the scripts that drive the movement of the platforms like horizontal, vertical movement, and spin.
The two character controllers share the same component called
CustomKCC. This component has a
CustomKCCBehaviour asset with the virtual functions:
|Move||Uses the direction input value to define which is the direction of movement and its velocity.|
|Jump||Changes the Y velocity of the character controller.|
|UpdateKCC||Evaluate the physics query or do more queries if necessary and apply movement to the character.|
|AddBroadPhaseQuery||Adds to the broadphase the shape cast of the character controller.|
By overriding these functions it was possible to create different KCCs compatible with the implemented mechanics. Each system implements a specific game mechanic and there are components that contain the game state needed. Also, each system uses an asset that allows the user to tweak some of the specific mechanic parameters.
For example, the
BetterJumpSystem script is in the Systems folder. This system uses the
BetterJump component which is in the DSL folder. Also, it has a configuration script in the Assets folder called
Find all the configuration assets in the
Resources/DB/SampleConfig folder in the Unity project.
3rd Party Assets
The 2D Platformer includes CC0 assets. The full packages can be acquired for your own projects at their respective site:
- 16x16 Industrial Tileset by 0x72