How do I do this? I can move between idle and walk blahbalh but i can't get the jump animation to work. The character controller is not on the same GameObject as the model (that has the the animation script). How do I check if it is grounded. and if not play the anim??
The character controller offers a variable isGrounded
var isGrounded : bool Description
Was the CharacterController touching
the ground during the last move?
function Update () {
var controller : CharacterController = GetComponent(CharacterController);
if (controller.isGrounded)
print("We are grounded");
}
This variable should solve your problem. However if you don't want to use the character controller component you may use Physics.Raycast
static function Raycast (origin :
Vector3, direction : Vector3, distance
: float = Mathf.Infinity, layerMask :
int = kDefaultRaycastLayers) : bool
Parameters origin The starting point
of the ray in world coordinates.
direction The direction of the ray.
distance The length of the ray
layerMask A Layer mask that is used to
selectively ignore colliders when
casting a ray. Returns
bool - True when the ray intersects
any collider, otherwise false.
Description
Casts a ray against all colliders in
the scene.
function Update () {
var fwd = transform.TransformDirection (Vector3.forward);
if (Physics.Raycast (transform.position, fwd, 10)) {
print ("There is something in front of the object!");
}
}
As you can see the layer is an optional parameter. Don't worry about it. By using Physics.Raycast() you can cast a ray down, if something was hit, the function will return true. Just adjust the distance (length of the ray) to your characters size and the return value can be used to see wether you're grounded.