O'Reilly logo

Unity 3.x Game Development Essentials by Will Goldstone

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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"), ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required