I’ve been working on a movement script that allows my player to move, jump, climb walls, and wall jump. I’ve run into this problem where after the player has been climbing, the wall jump only moves the player on the y-axis, and they don’t move out.
Here is my wall script so far:
void CheckSurroundings()
{
isGrounded = Physics2D.OverlapCircle(groundCheck.position, groundCheckRadius, whatIsGround);
isTouchingFront = Physics2D.OverlapCircle(frontCheck.position, wallCheckRadius, whatIsWall);
isTouchingClimbableFront = Physics2D.OverlapCircle(frontCheck.position, wallCheckRadius, whatIsGround);
notOnLedge = Physics2D.OverlapCircle(ledgeCheck.position, wallCheckRadius, whatIsGround);
}
void WallMechanincs()
{
if (isTouchingClimbableFront && Input.GetKey(KeyCode.X))
{
wallGrab = true;
}
if (!isTouchingClimbableFront || !Input.GetKey(KeyCode.X))
{
wallGrab = false;
}
if (!notOnLedge && wallGrab && Input.GetKey(KeyCode.UpArrow))
{
rb.position = ledgeCheck.position;
}
if (wallGrab)
{
if (!wallJumping)
{
rb.gravityScale = 0;
if (Input.GetKey(KeyCode.UpArrow))
{
rb.velocity = new Vector2(rb.velocity.x, wallClimbSpeed);
}
else if (Input.GetKey(KeyCode.DownArrow))
{
rb.velocity = new Vector2(rb.velocity.x, -wallClimbSpeed);
}
else
{
rb.velocity = new Vector2(rb.velocity.x, 0);
}
}
}
else
{
rb.gravityScale = originalGravity;
}
if (isTouchingFront && !isGrounded && moveInput != 0)
{
wallSliding = true;
}
else
{
wallSliding = false;
}
if (wallSliding)
{
rb.velocity = new Vector2(rb.velocity.x, Mathf.Clamp(rb.velocity.y, -wallSlidingSpeed, float.MaxValue));
}
if (Input.GetKeyDown(KeyCode.Space) && wallSliding || Input.GetKeyDown(KeyCode.Space) && wallGrab)
{
wallJumping = true;
Invoke(nameof(SetWallJumpingToFalse), wallJumpTime);
}
if (wallJumping)
{
rb.velocity = new Vector2(xWallForce * -moveInput, yWallForce);
}
}
void SetWallJumpingToFalse()
{
wallJumping = false;
}
}
Here’s the full code: May 25, 2021 - Codeshare
Any help would be greatly appreciated! Thanks in advance!