Maintain height/Altitude/distance from ground?

Hi, How can i make something maintain a certain distance between the ground and the player? ( something like a hovercraft ) I tried raycasting below the object and adding force to it when its lower than a certain distance, but it looks odd with the bumping and its not very smooth since i wanted to move the object around, like a racing game. THANKS!

I would probably do what you mentioned in your original answer. Did you do it right? I guess I would do something like this (not tested):

var height: float = 5.0;
var forceMultiplier : float = 10.0;

function FixedUpdate(){

    var hit : RaycastHit;

    if(Physics.Raycast(transform.position, -transform.up, hit, height)){
        rigidbody.AddForce(transform.up*(forceMultiplier/(hit.distance/2)));
    }

}

Some Notes:

1) I'm using FixedUpdate(), don't forget to use FixedUpdate() for applying rigidbody forces.

2) Make sure you set freeze rotation on the rigidbody.

3) By dividing forceMultipler by (hit.distance/2), I am attempting to apply a force relative to the length of the ray (the height off the ground). So the lower the hovercraft goes, the more upward force is applied to balance it out. This was just a crappy theory, I'm no math whiz, but I played around with some different numbers and this looks pretty good. You could try tweaking it or just changing the formula and see what happens.

There are two ways I can see to do this.

You can either add a character controller that extends a bit downward, then use Move and/or SimpleMove to move around.

Or you can add a collider, set it as trigger and add upwards force if it hits the ground:

function OnTriggerEnter(other:Collider){
  // if other == floor start applying upwards force
}

function OnTriggerEnter(other:Collider){
  // if other == floor stop applying upwards force
}