rigidbody.Addforce the force doesnt apply?

I’ve tried several methods in making a good jump function, but I can somehow not get it right. I’ve tried to use physics.rigidbody.AddForce…The debug.log works fine and says “SPACE!” But in game the character wont react.

using UnityEngine;
using System.Collections;

// Require a character controller to be attached to the same game object
[RequireComponent(typeof (CharacterController))]
[AddComponentMenu("Third Person Player/Third Person Controller")]

public class Movement : MonoBehaviour {

    public float rotationDamping = 20f;
    public float runSpeed = 10f;
    public int gravity = 20;
    public float jumpSpeed = 8;
    bool canJump;
    float moveSpeed;
    float verticalVel;  // Used for continuing momentum while in air    
    CharacterController controller;

    void Start()
        controller = (CharacterController)GetComponent(typeof(CharacterController));
    float UpdateMovement()
        // Movement
        float x = Input.GetAxis("Horizontal");
        float z = Input.GetAxis("Vertical");
        Vector3 inputVec = new Vector3(x, 0, z);
        inputVec *= runSpeed;
        controller.Move((inputVec + Vector3.up * -gravity + new Vector3(0, verticalVel, 0)) * Time.deltaTime);
        // Rotation
        if (inputVec != Vector3.zero)
            transform.rotation = Quaternion.Slerp(transform.rotation, 
                Time.deltaTime * rotationDamping);
        return inputVec.magnitude;
    void FixedUpdate()
        // Check for jump
        if (controller.isGrounded )
			Debug.Log ("you are grounded");
            canJump = true;
            if ( canJump && Input.GetKeyDown("space") )

				Debug.Log ("SPACE!");
                // Apply the current movement to launch velocity
               rigidbody.AddRelativeForce(transform.up * 2, ForceMode.Impulse);
            // Apply gravity
            verticalVel += Physics.gravity.y * Time.deltaTime;
        // Actually move the character
        moveSpeed = UpdateMovement();  
        if ( controller.isGrounded )
            verticalVel = 0f;// Remove any persistent velocity after landing

Since you improved your question and code so much (though the code still has a few style issues)…

CharacterController disables Rigidbody physics on your object (try it; an object with a rigidbody with gravity (just so it is easy to test as it should fall) on won’t move with a CharacterController attached even if it is disabled).

So, you have 3 options:

  1. Take out your character controller and use only rigidbody to get your desired behaviors.
  2. Take out rigidbody and try to simulate physics with position moving and velocity modifying.
  3. Complain to Unity Technologies that they should work together.

Number 3 is a little extreme and probably won’t get your problem solved any time soon. So go with number 1 or 2.

Which one you pick is dependent on which is more important, the CharacterController or the Rigidbody, and how much can the component behavior be imitated in code. If you only need the Rigidbody for jumping and gravity, I would stick with using the CharacterController.