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)

Yes that's right Md_Reptile. I am hitting the wall, detecting it and jumping straight up. Okay I haven't done a hit normal before so that's probably my problem ill look into that. As for the last part maybe I am doing it wrong. I'm trying to make it so the player only has about a 1/4 second to react to wall jump after they hit the wall.

1 Answer

1

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) {

I saw the first part, but thought he wanted to constantly move forward while airborne. The first line is useless, because the line below does cancel it out though doesn't it. Good eye tbkn