Programming Wall Climbing

Basically, lets say the surface of the wall is "latchable" (which would really be a box collider in my case adjusted to the side of the wall.) I already had assistance with latching onto a ledge and being able to move left and right on it. http://answers.unity3d.com/questions/18430/ledge-hanging-help-box-triggers-are-being-used

I figured in theory that if I copied the code and tweaked it to allow the player to move up and down it would work out. For some reason, it ignores the code that lets me go left and right and now I can only go up and down.

Here is a snippet:

  // Wall Movement controls
    if (onWall && wallTransform)
    {
        // Lock camera for short period when transitioning moving & standing still
        lockCameraTimer += Time.deltaTime;
        if (isMoving != wasMoving)
            lockCameraTimer = 0.0;

        // We store speed and direction seperately,
        // so that when the character stands still we still have a valid forward direction
        // moveDirection is always normalized, and we only update it if there is user input.

        //If the camera is behind/beside, right is right. Otherwise, right is left.
       if(Vector3.Dot(Camera.main.transform.forward, transform.forward) < 0)
        moveDirection = h * wallTransform.right;
            else
            moveDirection = h * -wallTransform.right;

            //If the camera is behind/beside, down is down. Otherwise, down is up.
        if(Vector3.Dot(Camera.main.transform.forward, transform.forward) < 0)
        moveDirection =v * -wallTransform.up;
        else
        moveDirection = v * wallTransform.up;
} 

Anyone else reading this likely won't know what h and v are and may not read the linked unityanswer, but that is irrelevant to the problem thankfully and they should still spot the problem easily.

Your problem is simple. You are reassigning the variable instead of adding to its existing value.

moveDirection = h * wallTransform.right;

moveDirection = v * wallTransform.up;

will set moveDirection to `v * wallTransform.up;`

In order to make the values add to one another, you should change it to

moveDirection += v * wallTransform.up;

Also, you don't need the `if(Vector3.Dot(Camera.main.transform.forward, transform.forward) < 0)` for the vertical movement. Unless your camera can rotate such that it is upside down (beware of gimbal lock if it can), down will always be down, and otherwise the code is wrong in that instance as it should be `if(Vector3.Dot(Camera.main.transform.up, transform.up) < 0)`.

So your code should look like:

// Wall Movement controls
if (onWall && wallTransform)
{
    // Lock camera for short period when transitioning moving & standing still
    lockCameraTimer += Time.deltaTime;
    if (isMoving != wasMoving)
       lockCameraTimer = 0.0;

    //If the camera is behind/beside, right is right. Otherwise, right is left.
    if(Vector3.Dot(Camera.main.transform.forward, transform.forward) < 0)
        moveDirection = h * wallTransform.right;
    else
        moveDirection = h * -wallTransform.right;

    moveDirection += v * wallTransform.up;
} 

Also, I recommend that when wall-climbing, you lock the camera in your camera script to be behind the character at all times. It depends on your script, but one easy way is to do the same check as above before moving your camera:

if(Vector3.Dot(target.transform.forward, transform.forward) < 0)
    //move the camera however you are moving your camera
else
    //stop the camera at the closest position/angle behind/beside your target