Trigger Ladder climbing only when there is moveInput.y

Hello,

I’m trying to extend the climbing functionality, so we need to input a direction on the axe y to trigger climbing. The goal is to be able to jump through a ladder without automatically start climbing.

This is my try so far :

    void ClimbLadder()
    {
        bool isClimbing = false;
        if (!myCapsuleCollider.IsTouchingLayers(LayerMask.GetMask("Climbing"))) 
        { 
            myRigidbody.gravityScale = gravityScaleAtStart;    
            return;
        }

        
        if (moveInput.y != 0)
        {
            Debug.Log(moveInput.y);
            isClimbing = true;
            Vector2 climbVelocity = new Vector2 (myRigidbody.velocity.x, moveInput.y * climbSpeed);
            myRigidbody.velocity = climbVelocity;
            myRigidbody.gravityScale = 0f;    
        }
        if (isClimbing)
        {
            myRigidbody.gravityScale = 0f;   
        }

    }

I’m a complete beginner in c#…

Hi Kaherdin,

Welcome to our community! :slight_smile:

Good job on challenging yourself. Does your code work?

Privacy & Terms