Hello everyone, I have seen alot of stuff on 2d ladder climb but none too helpful so I need some advice with this one, coming from XNA and the ladder climb I found on there is a whole different: but here I go this is what I have for code so far but just looking at the various post:
Now for the first part when I enter the trigger for the ladder he continues to slide right through it so I might just do a collision instead of a trigger. I have two cubes and called them ladder and then I made them triggers, now my second part is that he does the animation for the ladder climb but his position never changes and I could have misunderstood the scripting manual but I thought that this was suppose to change the position of the object to go up like for a ladder climb? If that makes any sense, but any help is appreciated.
Alright, I got the 2d character to climb, it was easier than I thought but the problem is that when he is in the trigger, he wants to continue to slide right or left, any ideas anyone?
My bad I thought that one was the right one, here it is man, now this worked for me, still may need to be tweaked for some but here it goes:
//update the climbing animation
public void UpdateClimb()
{
//condition evaluated if true
//call the correct button and perform the animations.
if(isClimbing )
{
//this is up
if(Input.GetAxis("Vertical") > 0)
{
//turn off gravity
movement.gravity = 0;
//move up the ladder at a slow pace
//did that for testing
transform.Translate(0,1 * Time.deltaTime,0);
SendMessage("onClimb",SendMessageOptions.DontRequireReceiver);
}
//this is down
else if(Input.GetAxis("Vertical") < 0)
{
movement.gravity = 0;
transform.Translate(0,-1 * Time.deltaTime,0);
SendMessage("onClimb",SendMessageOptions.DontRequireReceiver);
}
else
//if you are not moving then just go idle on the ladder
SendMessage("onClimbIdle",SendMessageOptions.DontRequireReceiver);
}
}
//enter the trigger
public void OnTriggerEnter(Collider col)
{
if(col.gameObject.tag == "Ladder")
{
isClimbing = true;
}
}
//exit the trigger
public void OnTriggerExit(Collider col)
{
if(col.gameObject.tag == "Ladder")
{
isClimbing = false;
movement.gravity = 60.0f;
}
}
If anyone else has gotten this to work for themselves, post it and if you have suggestions to make it better please post that also. I have it to work but not perfect and I posted it to the community in case others needed it and others have a better idea.
What is movement? It’s undefined. How to set your character gravity 0?
If I do it with Physics2D.gravity = Vector2(0,0); it set also the gravity of the enemy’s to 0.
I solve it this way:
In character controller script i wrote:
void OnTriggerEnter2D(Collider2D other)
rigidbody2D.gravityScale = 0; // turn off the gravity
void OnTriggerExit2D(Collider2D other)
rigidbody2D.gravityScale = 3; // turn on
But it’s still got issue
It does not want to stop in the middle of ladder.
I know this is an old thread but I thought I’d add my thoughts, the way I handled it, was I check to see if my character was a) at the ladder then b) touching the ground. If he was touching the ground and the ladder he could move in the x, if he was touching the ladder but not the ground I froze his x movement. I also set the gravity scale to 0 while touching the ladder that kept him from slowly sliding down the ladder. I changed the layers to allow him to pass through layers he would typically not be able to pass through (climbing through the ground).
These are checks I ran to dectect the status of what the character was touching.