Unity 3 - Disabling strafe when using First person Controller - JavaScript PDF Print E-mail

Let's see how to disable strafe in Unity's First person Controller.

Essentially, strafing is the act of moving laterally, without changing the camera direction.

To do that, we just need to make a little modification to the FPSInputController script.

You'll find it under "Standard Assets -> Character Controllers -> Sources -> Scripts" folder.

We need to modify the first statement of the Update method. The original one is this:

{codecitation}

var directionVector = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));

{/codecitation}

By default, the "Horizontal" axis is linked to our "a" and left arrow button for negative values, and "d" and right arrow button for positive values, and it is clearly the one we need to remove from our script.

So, we'll modify this statement, in this way:

{codecitation}

var directionVector = new Vector3(0, 0, Input.GetAxis("Vertical"));

{/codecitation}

Save the script, and we're done!

 

Add comment


Security code
Refresh