How to create smooth jump with rigidbody.addforce?

So I am trying to make my character jump with rigidbody.addforce, but it doesn’t work. Here is the code(c#):

public class Jump2 : MonoBehaviour {

public CharacterController controller;

public float thrust = 5.0f;

public Rigidbody rb;

// Use this for initialization

void Start () {
    controller = GetComponent<CharacterController>();

    rb = GetComponent<Rigidbody>();
}

// Update is called once per frame
void Update () {
    if(Input.GetButton("Jump") && controller.isGrounded)
    {
        rb.AddForce(transform.up * thrust, ForceMode.Impulse);
    }

}

}

2 Answers

2

I think I have found an answer. It appears that when the object also has a character controller the script doesn’t work for some reason.

That line should probably read: SceneManager.LoadScene("MainMenu1");

Did you fix it? I’m going through same problem now

Thank you ByteSheep! That worked! The only reason it had string and no quotations was because I was making a function for the main menu to load a scene and mixed up the parameters of the function with loading the actual scene since I use my other scripts as reference, thanks!