Cobbling together a character controller

Hello, folks. I’m a brand new developer and coding is definitely the thing I’m weakest at, but I’m determined to teach myself up to at least basic competence. Right now I’m trying to build a simple first-person character controller for use in future projects. It currently exists as the following scripts, which are pretty much unmodified from Holistic3d’s tutorial:

CheckButtons looks for key presses and turns them into translation, while locking that translation to delta time

using UnityEngine;
using System.Collections;

public class CheckButtons : MonoBehaviour {

   public float walkingspeed = 1.5f;

   void Start () {
     Cursor.lockState = CursorLockMode.Locked;   
   }

   void Update () {

     float translation = Input.GetAxis ("Vertical") * walkingspeed;
     float strafe = Input.GetAxis ("Horizontal") * walkingspeed;
     translation *= Time.deltaTime;
     strafe *= Time.deltaTime;

     transform.Translate (strafe, 0, translation);

     if (Input.GetKeyDown ("escape"))
       Cursor.lockState = CursorLockMode.None;
   }
}

Mouselook interprets mouse movement and rotates the camera (for up/down movement) or character (for left/right movement) as necessary, while smoothing it.

using UnityEngine;
using System.Collections;

public class Mouselook : MonoBehaviour {

   Vector2 mouseLook;
   Vector2 smoothV;
   public float sensitivity = 2.0f;
   public float smoothing = 2.0f;

   GameObject character;

   void Start ()
   {
     // This causes the "character" GameObject to be the parent of the camera the script is applied to
     character = this.transform.parent.gameObject;
   }

   void Update ()
   {
     var md = new Vector2(Input.GetAxisRaw("Mouse X"), Input.GetAxisRaw("Mouse Y"));

     md = Vector2.Scale (md, new Vector2 (sensitivity * smoothing, sensitivity * smoothing));
     smoothV.x = Mathf.Lerp (smoothV.x, md.x, 1f / smoothing);
     smoothV.y = Mathf.Lerp (smoothV.y, md.y, 1f / smoothing);
     mouseLook += smoothV;

     transform.localRotation = Quaternion.AngleAxis (-mouseLook.y, Vector3.right);
     character.transform.localRotation = Quaternion.AngleAxis (mouseLook.x, character.transform.up);
   }
}

I’m at the point where I sorta understand most of what is happening here. Slap the first one on a capsule with X and Z rotation of the rigidbody locked and the second one on a child camera of that capsule and you can wander around the world wherever you want. Next I need to figure out how to add the following:

-Lock the camera so that you can’t flip it upside-down, you can only look straight up or straight down at most.
-Dip the camera slightly when walking (a less obnoxious alternative to headbob)
-Simple sprint, increasing speed to around 5 while holding shift.

This controller will likely never need to duck or jump, and likely won’t ever need to be effected by physics beyond gravity.

I’m still plugging away at this, but I’m still so new to coding that I can barely figure out how to read the documentation, so any advice is appreciated. One specific question I have: What exactly is the “character controller” component added to the default asset FPS controller in addition to the script? I don’t see how it relates to what’s in the script, and my own script seems to work fine without it.

First of all, I’d like to point out, that this tutorial is really bad. Having a code ready and then explaining it is a surefire way to make your followers stop the video and copy the whole thing like an elementary student. And I don’t even want to talk about that GetKeyDown(“Escape”) line and the fact that he uses var in a C# code

So, your problems:
Camera locking can be easily solved, just create a public boolean variable called something like isLocked, put the GetKeyDown(“Escape”) line to the front of the mouselook, then replace the cursorstate line with the inverting of the boolean variable :
isLocked = !isLocked;
Now put an if statement after the GetKey, but before var md = …, that if isLocked is true should return
( if(isLocked) return )

Camera dipping should be solved with an animation I think

Sprint:

float translation = Input.GetAxis("Horizontal")
if player holds donw shift
    translation * walkSpeed
else
    translation * runSpeed
using UnityEngine;
using System.Collections;

public class CheckButtonsWithRunning : MonoBehavior {

   public float walkingspeed = 1.5f;
   public float runningspeed = 5f;

   void Start () {
     Cursor.lockState = CursorLockMode.Locked;
   }

   void Update () {

     float translation = Input.GetAxis ("Vertical");
     if (Input.GetKeyDown ("Shift"))
     {
     translation * runningspeed;
     }
     else
     {
     translation * runningspeed;
     }
     float strafe = Input.GetAxis ("Horizontal") * walkingspeed;
     translation *= Time.deltaTime;
     strafe *= Time.deltaTime;

     transform.Translate (strafe, 0, translation);

     if (Input.GetKeyDown ("escape"))
       Cursor.lockState = CursorLockMode.None;
   }
}

So after re-watching the introduction tutorials again and again and spending several hours randomly scattering curly braces around I’m still getting “The type or namespace name ‘translation’ could not be found” errors on lines 19 and 23 for this code. This is probably extremely obvious, but can anyone tell me why this isn’t working?

Also for some reason I’m now suddenly getting a “The type or namespace name ‘MonoBehavior’ could not be found” error on line 5 now despite my header being exactly the same as it was before…