Can anyone help me fix my ladder?

I am trying to make a ladder and there are no errors being displayed but it doesn’t work. When the rigidbody of the player collides with the 2D collider of the ladder, the gravity should turn off. I have tried 2 equals instead of 3 and also:

    if (canClimb === true) {
        print("WORKING");
        //var rb = RigidBody2D;
        
        rb.gravityScale = 0;

        if (Input.GetKey(KeyCode.UpArrow)) {// && canClimb == true) {
            transform.Translate(Vector3.up * 5 * Time.deltaTime);
        }
    }
    else {
        rb.gravityScale = 1;

    }

    //if (Input.GetKey(KeyCode.Space)) {
    //    transform.Translate(Vector3.up * 5 * Time.deltaTime);
    //}


}

function OnTriggerEnter2D (LadderCol) {
    print("Enter");
    if (tag === "LadderCollider") {
        canClimb = true;
    }
}

function OnTriggerStay2D (LadderCol) {
    print("Stay");
    if (tag === "LadderCollider") {
        canClimb = true;
    }
}

function OnTriggerExit2D (LadderCol) {
    print("Exit");
    if (LadderCol.tag === "LadderCollider") {
        canClimb = false;
    }

    
        //if (Input.GetKey(KeyCode.UpArrow)) {
        //    transform.Translate(Vector3.up * 5 * Time.deltaTime);
}

Thanks.

Heya,

there are no errors when I run it

What about your debug messages? Do they get displayed, aka does the trigger event actually happen? If not, check the following things:

  1. Is the rigidbody an actual rigidbody2d? I dont think a 3d rb can collide with a 2d collider
  2. Did you have a look at the collider matrix at the end of the page? Not every combination of RB and Collider actually send trigger messages. There is a difference between “OnCollisionEnter()” and “OnTriggerEnter()”.

I also assume that both objects are on the same layer, or that the layer collision is enabled.

hi @LittleLozza12 ,
according to your description i guess your trigger is not working right?
please check how much time your player is taking to reach the ladder, and check the sleep threshold of the ladder, one of the reason can be your ladder’s rigidbody is going in the sleep state while the player is reaching there.
if it is so, try reducing the distance and check the if the trigger is working or not.
sleep threshold you can check here-> edit/project settings/ physics

I just changed it slightly and put it in a new C# file instead of a Javascript one and it worked. I then added it to the player and my ladder now almost fully works.