- Home /
The question is answered, I posted what I did to get it to work.
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.
Answer by LittleLozza12 · Jan 11, 2019 at 11:43 AM
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.
Answer by Klarzahs · Jan 08, 2019 at 10:04 AM
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:
Is the rigidbody an actual rigidbody2d? I dont think a 3d rb can collide with a 2d collider
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.
I don't have any debug messages which is why I'm not sure if it knows it's collided. The rigidbody is definitely a 2D one and the collider is a box collider 2D. I have tried changing the ontriggerenter to oncollisionenter but still nothing. They are not on the same layer but my sprite/character works with my other colliders as the ground and platforms are colliders on the same layer as my ladder but I'm able to walk along them all. Thanks.
@LittleLozza12 Does your player have a Collider as well? If you look at the matrix again, a static collider (aka your ladder) only fires collision with a rigidbody collider (aka a rb with a collider)
Yeah, my player also has a collider. And it's set so that it's always active, not on trigger like my ladder is.
Answer by upasnavig90 · Jan 08, 2019 at 10:11 AM
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
Thanks, I've just checked the sleep threshold for all my colliders and rigid bodies and changed them but that made no difference either.