- Home /
Wall Jumping Help
I've been trying to figure out a way to put in a simple wall jumping system for my platformer. I was trying to use OnControllerCollider hit to detect wall collision with tags, the only problem is making the player jump in the opposite direction of the wall in the "WallJump" function. Can anyone help?
function Awake(){
controller = GetComponent(CharacterController);
}
function Update(){
if(controller.velocity.sqrMagnitude < 0.1){
//animation.CrossFade("IdleAni");
}
if(controller.velocity.sqrMagnitude > moveSpeed){
moveSpeed = moveSpeed; //Limits excess directinal speeds by multiple button presses
}
forward = Camera.main.transform.TransformDirection(Vector3.forward);
forward.y = 0;
forward = forward.normalized;
right = Vector3(forward.z,0,-forward.x);
h = Input.GetAxis("Horizontal");
v = Input.GetAxis("Vertical");
//MAINTAIN Y OF MOVE DIRECTION
var XZmoveDirection:Vector3 = (h * right + v * forward);
XZmoveDirection *= moveSpeed;
moveDirection.x = XZmoveDirection.x;
moveDirection.z = XZmoveDirection.z;
if(controller.isGrounded){
canDoubleJump = true;
if(Input.GetButtonDown("Jump") && canJump){
Jump();
}
if(Input.GetKeyDown(KeyCode.LeftShift) && dash){
Roll();
}
}
if(!controller.isGrounded){
if(canDoubleJump && canJump && Input.GetButtonDown("Jump")){
DoubleJump();
}
if(Input.GetKeyDown(KeyCode.LeftShift)){
AirDash();
}
}
if(XZmoveDirection != Vector3.zero){
var rotation0 = transform.rotation;
rotation0.SetLookRotation(new Vector3(moveDirection.x,0,moveDirection.z) * rotateSpeed);
transform.localRotation = rotation0;
}
if(!controller.isGrounded){
moveDirection.y -= gravity * Time.deltaTime * 2;
}
controller.Move(moveDirection * Time.deltaTime);
}
function OnControllerColliderHit(hit : ControllerColliderHit){
if(hit.collider.tag == "Wall" && !controller.isGrounded && Input.GetButtonDown("Jump")){
WallJump();
}
}
function WallJump(){
//WHAT DO I PUT HERE?!
}
I forgot to mention that this is a game in 3D, and that I'm using a character controller, no rigidbodies or physics.
Thanks!
Answer by Spinnernicholas · Jun 11, 2014 at 07:59 PM
The ControllerColliderHit object has vector data about the direction of the collision. Pass collision vector into the walljump function.
Add jumpUpAmount x Vector3.Up to the collision vector. By changing jumpUpAmount , you can change the angle of the jump.
Normalize the resulting Vector.
Multiply that by jumpPower.
Apply the final vector as an instantaneous force to the controller.
I have a limited idea of what I'm actually doing here, this does little though: function WallJump(){ wallObject + jumpHeight Vector3.up.normalized jumpHeight; }
Your answer
Follow this Question
Related Questions
Difficulty with rolling my own platformer script 2 Answers
Smoothing out jumping? 1 Answer
The Mario Jump? 2 Answers
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
2.5D Platformer - Jump Question 1 Answer