Trying to get my wall Jump to Work

Hey Guys. I’m trying to get my wall jump to work. Right now my character is only jumping straight into the air when he hits the wall. I want him to bounce the other direction he was moving when he jumps onto the wall? What kind of script would I use to do this? I’ve been trying to figure it out and cant. Take a look at the code I have so far.

private var canWallJump : boolean=false;
private var canWallJumpTime : float = 0;

var speed : float = 10.0;
var jumpSpeed : float = 10.0;
var gravity : float = 20.0;


    
    function Update () {    	
    	
    	var fwd = transform.TransformDirection (Vector3.forward);
        var controller : CharacterController = GetComponent(CharacterController);
       
       
           if (controller.isGrounded == false){
        		moveDirection = Vector3(Input.GetAxis("Vertical"),0);
        		moveDirection = transform.TransformDirection(moveDirection);
        		moveDirection *= speed;
        		canWallJump = true;
				canWallJumpTime = Time.time;
		//		canWallJumpDir = Vector3.Scale(Vector3(-1,0,-1), lastDirection);
				if(Time.time - canWallJumpTime > .25) canWallJump = false;
        		if(Physics.Raycast(transform.position, fwd, 1 && Input.GetButton("Jump") && canWallJump)) {
            		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);
	
	//last direction before wall contact
//	lastDirection = movement;
  }
	
@script RequireComponent (CharacterMotor)

There are some problems that I find with your code, hopefully one of them will fix your issue:

           moveDirection = Vector3(Input.GetAxis("Vertical"),0);
           moveDirection = transform.TransformDirection(moveDirection);
           moveDirection *= speed;

In this code you’re setting moveDirection to be similar to the input, but then you immediately override it with the forward direction, so the input is basically ignored.

if(Physics.Raycast(transform.position, fwd, 1 && Input.GetButton("Jump") && canWallJump)) {

Here it seems like you forgot one parenthesis. You are && the distance (1) with the input stuff. Try this instead:

if(Physics.Raycast(transform.position, fwd, 1) && Input.GetButton("Jump") && canWallJump) {