- Home /
3d wall jumping with charter controller
im making a 3d Platformer with unity's built-in charter controller and no mater what I try I can't seem to get wall jumping right. The player jumps but he doesn't jump off the wall to the opposite side he just stays on the wall. NOTE: this is not the entire script because the script is too long to include it all so I only included the parts that involve the wall jump. This is what I have:
void OnControllerColliderHit(ControllerColliderHit hit)
{
hitNormal = hit.normal;
}
void WallJump()
{
velocity.y = Mathf.Sqrt(maxJumpHight * -2 * gravity);
animator.SetBool("Jumping", true);
wallJumping = true;
woosh1.Play();
jump.Play();
movingPlatform.enabled = false;
canMove = false;
StartCoroutine(CanMoveAgain());
}
float horizontal = moveing.x;
float vertical = moveing.y;
Vector3 direction = new Vector3(horizontal, 0f, vertical).normalized;
if (direction.magnitude >= 0.1f && canMove)
{
if (wallJumping == true)
{
direction = -hitNormal;
controller.Move(hitNormal * speed * Time.deltaTime);
}
if (!wallJumping == true)
{
float targetAngle = Mathf.Atan2(-direction.x, direction.z) * Mathf.Rad2Deg + cam.eulerAngles.y;
float angle = Mathf.SmoothDampAngle(transform.eulerAngles.y, targetAngle, ref turnSmoothVelocity, turnSmoothTime);
transform.rotation = Quaternion.Euler(0f, angle, 0f);
Vector3 moveDir = Quaternion.Euler(0f, targetAngle, 0f) * Vector3.forward;
controller.Move(moveDir.normalized * speed * Time.deltaTime);
}
}
it just doesn't work what do I do?
Answer by MUG806 · Feb 16, 2021 at 09:08 AM
Edit: Think I found your problem. In WallJump you do:
but then your code to move in the direction of the wall normal is inside this if statement:canMove = false;
which requires canMove to be true. You either need to change the if statement, move the wall jump code outside of it, or not set canMove to false.if (direction.magnitude >= 0.1f && canMove)
Old wrong answer:
I see you've written a "WallJump" method which looks fine, but I dont see you actually calling it anywhere. Is there some code you haven't included where you trigger your wall jump to happen? If not I think you just forgot to do that. Somewhere when you detect if the player is against a wall and trying to jump you need to have the line:
WallJump();
I imagine your problem is in that section of code, so if you don't include it I can't really help.
I know it's not the problem cuz I jump but I don't jump off the wall but here:
getting the input:
private void Awake()
{
controls = new PlayerControls();
controls.GamePlay.Jump.performed += ctx => Jumping();
controls.Extra$$anonymous$$ovement.GroundPound.performed += ctx => TriggerButton();
controls.Extra$$anonymous$$ovement.GroundPound.canceled += ctx => TriggerButtonCanceled();
}
checking if I can jump:
void Jumping()
{
var hitAngle = Vector3.Angle(Vector3.up, hitNormal);
if (isGrounded && canWalkOnSlope)
{
Jump();
}
else if (isGrounded && !canWalkOnSlope && hitAngle >= 71 && hitAngle <= 110)
{
WallJump();
}
}
and jumping:
void WallJump()
{
velocity.y = $$anonymous$$athf.Sqrt(maxJumpHight * -2 * gravity);
animator.SetBool("Jumping", true);
wallJumping = true;
woosh1.Play();
jump.Play();
movingPlatform.enabled = false;
can$$anonymous$$ove = false;
StartCoroutine(Can$$anonymous$$oveAgain());
}
Your answer
Follow this Question
Related Questions
Jumping away from a wall 1 Answer
problems setting up wall jump 1 Answer
Adding force to the charactercontroller for walljump 1 Answer
Unity2D Platformer - Wall jumping with unity's physics 1 Answer
HELP! stuck on wall jump Unity 2D 1 Answer