So I’ve been working for hours trying to get this to work. Basically, I’m controlling a 2d character’s velocity and while on a ladder, their velocity is the yInput * climbingSpeed else; it’s just the y velocity. Jumping is being handled by setting the y velocity to “jumpForce”. The issue with everything is that the character doesn’t jump when I’m either touch the ladder nor actively climbing.
This is where the normal movement and climbing movement is done.
P.S. ApplyMovement() is called in FixedUpdate()
void ApplyMovement()
{
float crouch = (isCrouching) ? crouchMultiplier : 1f;
float run = 1;
//float run = (Input.GetKey(KeyCode.LeftControl)) ? runMultiplier : 1f; //Sprinting Value
//checks if touching ladder
if (Physics2D.OverlapCircle(groundCheck.position, GroundedRadius, whatIsClimbable)) { isClimbing = true; rb.gravityScale = 0f; }
else { isClimbing = false; rb.gravityScale = 3.5f; }
//Adding Force Horizontally (no Slope detected) and when not jumping nor pillarJumping
if (Physics2D.OverlapCircle(groundCheck.position, GroundedRadius, whatIsGround) && !isOnSlope &&/* !isJumping && */!isPillarJumping)
{
//jumpForce = 1f;
isJumping = false;
//performedJump = false;
movement.Set(movement.x + groundedspeed * xInput * crouch * run * slowMultiplier,
isClimbing ? (yInput * climbingSpeed) : rb.velocity.y);
movement.x *= (1 - groundedDamp);
}
//Adding Force towards Slope's direction (when Slope detected)
/*else if (Physics2D.OverlapCircle(groundCheck.position, GroundedRadius, whatIsGround) && isOnSlope && canWalkOnSlope && !isJumping && !isPillarJumping)
*{
* movement.Set(movement.x + groundedspeed * slopeNormalPerp.x * -xInput * crouch * run * slowMultiplier,
* movement.y + groundedspeed * slopeNormalPerp.y * -xInput * crouch * run * slowMultiplier);
* movement *= (1 - groundedDamp);
* rb.velocity = movement;
}*/
//Adding Force Horizontally and Mid-air Speed Multiplier
else {//gets here when holding jump before release
movement.Set(movement.x + midairspeed * xInput * crouch * run * slowMultiplier,
isClimbing ? (yInput * climbingSpeed) : rb.velocity.y);
movement.x *= (1 - midairDamp);
}
rb.velocity = movement;
}
This is where the values for jumping are done when the player presses jump
public void pressedJump(InputAction.CallbackContext obj)
{
jumpForce = 17f;
ActivateJumpValues();
}
public void ActivateJumpValues()//InputAction.CallbackContext obj)
{
if (!performedJump)
{
CatchMissedTimer = CatchMissedDuration;
performedJump = true;
//isJumping = false;
}
}
This is where the jumping is actually done when the player releases jump
public void releasedJump(InputAction.CallbackContext obj)
{
//jumpForce = 1f;
DoJump();
}
public void DoJump()//InputAction.CallbackContext obj)
{
if(!isPillarJumping) rb.velocity = new Vector2(rb.velocity.x, Mathf.Clamp(rb.velocity.y, -Mathf.Infinity, jumpReleaseClamp));
//CatchMissedTimer : the timer of the space input to stay registered (to register a jump when player is accidently pressing space before landing
//CoyoteTimer : the timer of grounded to stay registered (to avoid player pressed jump after walking off a cliff)
if (CatchMissedTimer > 0) CatchMissedTimer -= Time.deltaTime;
if (CatchMissedTimer > 0 && CoyoteTimer > 0 && !isPillarJumping)
{
isJumping = true;
//CatchMissedTimer = CatchMissedDuration;
CoyoteTimer = 0f;
rb.velocity = new Vector2(rb.velocity.x, jumpForce);
performedJump = false;
}
}