Building the creature – Controls
In order to move the (yet-to-be-designed) creature, some experimentation on it’s controls need to take place 1st. As per the initial idea, the creature is to be controlled with the 2 analog joysticks of a Xbox game pad. The creature’s movement is also constricted to the range of it’s 2 heads.
For this test, a square field was created, with the camera in an overhead, slightly tilted view downwards.
- Mapping of Xbox360 controller’s analog axes
Using references from a wiki page, I find that Unity registers the left analog as the X and Y axis already, while the right analog is referred to as the 4th and 5th axis. These can be found in the input manager in project settings. A script named JoyInput is created to listen for commands from the game pad.
- Translating axes to movement
Generic colored cube is used to represent one of the heads. They have the Rigidbody component applied, and will behave as if there is gravity in the game space. JoyInput receives inputs from the left analog and nudges the cube up/down or to the sides. Another cube is created for the 2nd player, and it’s movements controlled by the right analog stick.
- Working with spring joints – Connecting the creature
The Unity built-in spring joint component allows 2 rigid bodies to be connected together; If one of the linked object moves, the other will be stringed along. Also, a main ‘body’ is created and chained in between the 2.