Scripting the player movement
The game so far features an environment with collision data and a multipart player object that interacts and responds to this environment. The player, however, cannot yet be controlled, and this section explores controller functionality further. The user will have two main input mechanics, namely, movement (walking left and right) and jumping. This input can be read seamlessly and easily using CrossPlatformInputManager
, which is a native Unity asset package. This package was imported at the project creation phase, but it can be imported now via the application menu with Assets | Import Package | CrossPlatformInput. Once imported, open the Standard Assets
| CrossPlatformInput
| Prefabs
folder and drag and drop the MobileTiltControlRig prefab to the scene. This prefab lets you read input data across a range of devices, mapping directly to the horizontal and vertical axes that we've already seen in previous chapters. See Figure 5.44: