- Home /
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)
Answer by jayhatmaker · May 17, 2013 at 06:55 AM
When you think through the wall jump logic, it shouldnt be so difficult.
Jump.
Detect if the character hits a wall.
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?
I'm able to get the first two checks down I think, but unable to get the third. I'm not sure if my script from character controller is interfering or if this script is messed up.
You need to add something important to your script! The first person controller uses: if(canControl && lastTimeJumped < 0.2) on normal jumps. It should also be used for wall jumps, it made my walljumping so much smoother. ( Check Character $$anonymous$$otor script ).
I Can Get The First And Last Checks Only (I Don't $$anonymous$$now How To Detect A Wall.) Help.