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?