A code for climbing ladders only works when rigibody of player is kinematic

Im not sure if this is the right place but, I was following a youtube tutorial for building a ladder and the code only works when player’s rigibody is set to kinematic. However when it is on kinematic my player can’t move :confused: plus when I try exiting the box collider so the controller can climb it wont let me exit. Any help would be apreciated. Im trying to learn and thought the specific tutorial sereis would be a great place to start. Here is the code.

using UnityEngine;
public class Ladder : MonoBehaviour
{

    public Transform playerController;
    bool inside = false;
    public float speed = 3f;
    public FirstPersonController player;
    public AudioSource sound;





    void Start()
    {
        player = GetComponent<FirstPersonController>();
        inside = false;


    }



    void OnTriggerEnter(Collider col)
    {

        if (col.gameObject.tag == "Ladder")
        {
            Debug.Log("TouchingLadderTrue");
            player.enabled = false;
            inside = !inside;
        }


    }

    void OnTriggerExit(Collider col)
    {

        if (col.gameObject.tag == "Ladder")
        {
            Debug.Log("TouchingLadderFalse");
            player.enabled = true;
            inside = !inside;
        }


    }

    void Update()
    {
        if (inside == true && Input.GetKey("w"))
        {
            player.transform.position += Vector3.up /
            speed * Time.deltaTime;
        }

        if (inside == true && Input.GetKey("s"))
        {
            player.transform.position += Vector3.down /
            speed * Time.deltaTime;
        }

        if (inside == true && Input.GetKey("w"))
        {
            sound.enabled = true;
            sound.loop = true;
        }
        else
        {
            sound.enabled = false;
            sound.loop = false;
        }




    }


}

It sounds like you’re missing a step in the tutorial. None of us are going to watch it to try and guess what part you left out, but you are welcome to either:

  1. go back and check your work carefully, or

  2. learn how to debug and solve the problem using debugging.

The first is more mindless and requires you to essentially recheck each step.

The second will help you develop the single-most valuable programming skill: debugging.

By debugging you can find out exactly what your program is doing so you can fix it.

Use the above techniques to get the information you need in order to reason about what the problem is.

You can also use Debug.Log(...); statements to find out if any of your code is even running. Don’t assume it is.

Once you understand what the problem is, you may begin to reason about a solution to the problem.

Remember with Unity the code is only a tiny fraction of the problem space. Everything asset- and scene- wise must also be set up correctly to match the associated code and its assumptions.

If you do want to go the #1 mindless way, remember that “following a youtube tutorial” is NOT the correct approach. Try this instead:

Two steps to tutorials and / or example code:

  1. do them perfectly, to the letter (zero typos, including punctuation and capitalization)
  2. stop and understand each step to understand what is going on.

If you go past anything that you don’t understand, then you’re just mimicking what you saw without actually learning, essentially wasting your own time. It’s only two steps. Don’t skip either step.

Imphenzia: How Did I Learn To Make Games:

1 Like

Ah I see, Thanks for the advice! The “Can I” is super helpful I didnt even think of that, I use that method for music but looked at Game design in a different way. Thanks again :slight_smile: