- Home /
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)
@seanybaby2 I think I see, but I am sorta wondering what is actually happening when you use this code. You say that he jumps straight up when it happens, so like its making it as far as detecting the wall and then jumping straight up?
If its happening no problem that way, then it should be easy to just use the hit normal from a raycast onto the collided object (wall) and sort of lerp your character around real quick to that direction and continue forward movement.
Also I see you have moveDirection.y being set when you try to do this, but maybe ins$$anonymous$$d you need to be taking the normal of the raycast that just hit, and saying "rotate my character sorta fast to face opposite of this hit" sort of...
and ummm... the Time.time - camWallJumpTime part didnt make sense to me... was that supposed to be more like timeSinceFirstJumpingOffTheGround - timeUntilWereAllowedToWallJump?
Yes that's right $$anonymous$$d_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.
Answer by Tomer-Barkan · May 22, 2013 at 07:11 AM
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
Your answer
Follow this Question
Related Questions
get input slowly. 2 Answers
3d wall jumping with charter controller 1 Answer
Jumping away from a wall 1 Answer