|Articles & Tutorials|
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:
var directionVector = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
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:
var directionVector = new Vector3(0, 0, Input.GetAxis("Vertical"));
Save the script, and we're done!