Creating A wall Jump

Hey Guys, I’m trying to create a wall jump script that I have been stuck on for a while. I’m pretty new to using unityscript and coding in general and I’m trying to figure it out. Currently I am using the platformer controller that comes with unity script but I am trying to add this script to my object so he can wall jump. Thanks for your help.

private var canWallJumpDir : Vector3 = Vector3.zero;
private var moveDirection : Vector3 = Vector3.zero;
var speed : float = 26.0;
var jumpSpeed : float = 500.0;
var gravity : float = 20.0;


    
    function Update () {    	
    	
    	var fwd = transform.TransformDirection (Vector3.forward);
        var controller : CharacterController = GetComponent(CharacterController);
       
       
           if (controller.isGrounded == false){
        		// canWallJumpTime = Time.time;
        		moveDirection = Vector3(Input.GetAxis("Vertical"),0);
        		moveDirection = transform.TransformDirection(moveDirection);
        		moveDirection *= speed;
        		if(Physics.Raycast(transform.position, fwd, 1 && Input.GetButton("Jump"))) {
            		print("There is something in front of the object!");
            		moveDirection.y = jumpSpeed;
           	
        	}
        else{
        	print ("We are grounded");
        	}
        }
    // apply gravity
	moveDirection.y -= gravity * Time.deltaTime;
	
	// Move The controller
	controller.Move(moveDirection * Time.deltaTime);
  }
	
@script RequireComponent (CharacterMotor)

When you think through the wall jump logic, it shouldnt be so difficult.

  1. Jump.
  2. Detect if the character hits a wall.
  3. If jump key is hit while character is in air and touching the wall, jump again, but inverse the x-axis. (off from the wall)

So, in order to achieve a wall jump, you need 3 checks.

Are you in air?
Are you touching the wall (not ground)?
Is jump key hit again?