Ladder help?

So I’m making a ladder for my 2D game, and I spent about 3 hours trying to get it to work. I fixed it by making my player not kinematic, but this is making it phase through the floors whilst in contact with a ladder, is there any way around this?! Here is my code:

void Update ()
	{
		if(lBool.contactLadder == true)// If player is in contact with ladder
		{
			climbing = true;
		}
		else
		{
			climbing = false;
		}
		
		if(Input.GetKey(KeyCode.UpArrow)) // If Up Arrow is pressed
		{
			if(climbing)
			{
				transform.Translate(Vector3.up * pVars.climbSpeed * Time.deltaTime); // Move the player up
			}
		}
		if(Input.GetKey(KeyCode.DownArrow)) // If Down Arrow is pressed
		{
			if(climbing)
			{
				transform.Translate(Vector3.down * pVars.climbSpeed * Time.deltaTime); // Move the player down
			}
		}
		if(climbing)
		{
			rigidbody.isKinematic = true;
		}
		else
		{
			rigidbody.isKinematic = false;
		}
	}

Instead of using translate and having to disable the rigidbody, I think you can simply set the velocity of the player instead. Here’s the link to the scripting reference. Hope I helped :smile:

Note: Make sure the object’s isKinematic is false!

I’m not sure what the nature of your 2D game is. Here’s one way you can do it. I tested it out super quickly and it works well. Rather than disabling the rigidbody component, why not use the functionality of the rigidbody to your advantage?

        bool isClimbing = false;
	
	public float moveSpeed = 5f;


	//through a trigger or others means set the climb variable to true and gravity to false when you need to climb
	public void SetClimb(bool b)
	{
		isClimbing = b;
		rigidbody.useGravity = !b;
		
	}
	
	void Update () 
	{
	
	 	if(isClimbing)
		 rigidbody.AddForce(  Input.GetAxis ("Vertical") * moveSpeed *Vector3.up ) ;
		
		
		rigidbody.AddForce(  Input.GetAxis ("Horizontal") * moveSpeed *Vector3.right ) ;
		
	}

Here I’m using the addforce function of the rigidbody. You can find out more here:

Also, I find it much more streamlined to use the Input.GetAxis, which can be tweaked further in the input manager: