- Home /
Question by
Kolalamonkeys · May 25, 2021 at 11:02 PM ·
2dplatformerclimbingwall jump
Wall jump doesn't change on x axis
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: https://codeshare.io/Gb41Bj
Any help would be greatly appreciated! Thanks in advance!
Comment
Best Answer
Answer by Kolalamonkeys · May 26, 2021 at 04:07 AM
I found the answer. The wall jump was using -moveInput, but when there is no moveInput that means it will not move on the x. I need to change it to detect which wall the player is on and move the opposite direction.