The Infinite Runner Engine allows for the creation of a lot of different games. You can create a platformer runner, a plane game, a jumping cloud game, really the possibilities are endless (no pun intended). To accomodate for this wide range of possible gameplay styles for your player, the Engine includes a base PlayableCharacter class, used as a single interface by other classes, that you’ll need to extend if you want to create a new playstyle. Or you can simply reuse one of the existing example character controllers included in the asset. This page covers all that.
The PlayableCharacter class
The PlayableCharacter class is not meant to be added directly to a prefab/gameobject. It’s meant to be extended. However, it contains a lot of base methods, common to all player characters. It’ll take care of the hard work for you, namely:
- real time distance to the ground computation
- animator management and update
- death condition checks and death/respawn management
- input detection
- character bounds
- position reset
Make sure you have a look at the class if you’re interested in creating a unique playable character. It contains a lot of methods ready to be extended and covers most use cases.
Selecting a PlayableCharacter for your scene
In order to add a PlayableCharacter in your scene, you should not put the prefab actually in the scene. It’d work, but the LevelManager (and other game logic managers) wouldn’t know what the “real” player character is. Instead, select your scene’s LevelManager, and in its inspector you’ll see you can define a number of PlayableCharacters. Most games only have one, but you can have more if you want. Once you’ve defined the number of player characters you want, just drag a PlayableCharacter (or extended) prefab into the slot, and you’re done. If you have more than one character, you can also specify how far from each other they should spawn.
The Jumper is a relatively simple class that extends PlayableCharacter to allow it to jump, by overriding a few of its methods. It’s great for runner games like Canabalt for example, where a character runs, jumps a number of times, and can jump again after touching the ground.
Found in the FlappyCloud demo scene, this controller allows for an infinite number of jumps, with a forced and customizable cooldown between two jumps. You can define that and the jump’s direction and force from its inspector.
Extended from the Flappy controller, the Dragon controller is an example of a very specialized controller (found in the BackwardsDragon demo scene). It handles various specific animations and explosions.
Adds a vertical force while the button is pressed. Typically demoed in the SkyTheory demo scene.
Used in the SkyTheory demo scene, extends the Rocket controller and adds reactor smoke management, death explosion and other demo specific stuff.
Simply adds the specified force to the left/right when the player presses left or right.
A more complex version of the LeftRightMove controller, that allows for axis choice, inertia and other constraints.
Extends FreeLeftToRightMovement, and adds oscillatory flight movement, and rotation when turning left or right.
Accessing playable characters via script
The best way to access the player(s) via script is via the LevelManager class, as it keeps a reference to it at all times (or to them if you have more than one playable character in your level). From any class, you can access the player array via :
For example, this is how you’d access the rigidbody 2D of the first player character :