Scripting for character movement

This script is an example of a character control script that uses the Input class and CharacterController class' Move command to create character movement by manipulating a Vector3 variable.

Deconstructing the script

To test how much you have learned so far, take a look at the script in its entirety first, to see how much you can understand, then read on to see each part deconstructed.

Full script (Javascript)

The full deconstruction of the script is as follows:

var speed : float = 6.0; var jumpSpeed : float = 8.0; var gravity : float = 20.0; private var moveDirection : Vector3 = Vector3.zero; private var grounded : boolean = false; function FixedUpdate() { if (grounded) { moveDirection = Vector3(Input.GetAxis("Horizontal"), ...

Get Unity 3.x Game Development Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.