Grounding and Object

Hi, I’m writing in C#:

I am using the code sample found within the reference:

using UnityEngine;
using System.Collections;

public class Example : MonoBehaviour {
    public float speed = 6.0F;
    public float jumpSpeed = 8.0F;
    public float gravity = 20.0F;
    private Vector3 moveDirection =;
    void Update() {
        CharacterController controller = GetComponent<CharacterController>();
        if (controller.isGrounded) {
            moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
            moveDirection = transform.TransformDirection(moveDirection);
            moveDirection *= speed;
            if (Input.GetButton("Jump"))
                moveDirection.y = jumpSpeed;
        moveDirection.y -= gravity * Time.deltaTime;
        controller.Move(moveDirection * Time.deltaTime);

So, what’s my problem? Well, it would appear that my object is conditioned to move when grounded, which is fine. I was expecting my gravity variable: moveDirection.y -= gravity *Time.deltaTime to work and ground my object, but instead it hangs in space. So, my next cause of action was to try and ground the object manually through the coordinates, but this doesn’t work. Which means that within the context of my project and the context of this code, there must be a disagreement of sorts. My issue is that I can’t seem to work it out! My game is a simple cube which I’m trying to get to move left and right and jump. I can’t figure out why the code doesn’t work, any ideas?

I’ve been puzzling over this for days, trying numerous different methods all with limited success.

I tried and it works fine for me, have you tried to create a new cube and adding only your script with the charactr controller? Did you remore the box collider, sometimes having a collider and a character controller messes things up…