Hi, I’m new to Unity and as a learning exercise I’m trying to reproduce as many movement features from Celeste as possible, I have been fighting with walljumps the entire day but it seems like I have managed to make them work, except when a wall jump starts while you are grabbing the wall, the character jumps fine in the first half and then loses all velocity only on the X axis and simply falls down afterwards.
Here’s a drawing that illustrates my problem so it’s easier to understand.
Here’s the code involving wall jumping:
void wallGrab()
{
wallGrabbed = true;
if(DisableGrab == false)
{
rb.velocity = new Vector2(0f, vertical * moveSpeed * ClimbingSpeed);
rb.gravityScale = 0f;
}
}
void WallSlide()
{
isWallSliding = true;
rb.velocity = new Vector2(rb.velocity.x, -WallFriction);
}
void HandleWallJump()
{
if(isWallSliding || wallGrabbed) //Prepares the jump
{
isWallJumping = false;
wallJumpingDirection = -transform.localScale.x;
wallJumpingCounter = wallJumpingTime;
CancelInvoke("StopWallJumping");
}
else
{
wallJumpingCounter -= Time.deltaTime; //Counting the cooldown
}
if (Input.GetButtonDown("Jump") && wallJumpingCounter > 0f)
{
StartCoroutine("disableGrab");
isWallJumping = true;
if (wallGrabbed)
{
rb.velocity = new Vector2(wallJumpingDirection * wallJumpingPower.x, wallJumpingPower.y);
}
else
{
rb.velocity = new Vector2(wallJumpingDirection * wallJumpingPower.x, wallJumpingPower.y);
}
wallJumpingCounter = 0f;
if(transform.localScale.x != wallJumpingDirection)
{
isFacingRight = !isFacingRight;
Vector3 localScale = transform.localScale;
localScale.x *= -1;
transform.localScale = localScale;
}
Invoke("StopWallJumping", wallJumpingTime);
}
}
private void StopWallJumping()
{
isWallJumping = false;
}
I really have no idea why it behaves like that only if im grabbing the wall my best guess its that it has to do with gravity but as soon as I let go of the wall gravity is set back to normal so it shouldn’t matter.
Any help is greatly appreciated!!