check object if grounded

how can i check if the object is already grounded on the floor?

because my AI is flying while following its waypoint... i want him to stay on ground while following its path ...

here is the code

var waypoint:Transform[];

var speed:float=20;

private var cwaypoint : int;

var gravity=20.0;

private var grounded : boolean = false;

function FixedUpdate () {

var target:Vector3=waypoint[cwaypoint].position;
var moveDirection:Vector3=target-transform.position;

var velocity=rigidbody.velocity;


} rigidbody.velocity=velocity;



Yes, as mentioned, you should add a rigid body component to both the ground floor and the object that you want to check and see if it is grounded. You can then test for a collision between the two objects, and tell your AI what to do when a collision is detected, or not.

I'd say simply cast a ray downward, see what the RaycastHit.distance is, and if it exceeds a certain range add a downward force.