I have a character, box collider, and animations.
I have a level, mesh collider.
If the character falls on a Unity-crafted cube his scripted animations play fine, but if he falls on the level, none of his scripted animations play. Also, if I turn the mesh collider to be convex, his animations work, but he floats above the level in a strange way and has other incorrect behaviour. Here’s the code for animations:
var grounded = false;
function Update () {
var movement = Input.GetAxis("Horizontal");
if (Input.GetAxis("Horizontal") grounded) {
animation.Play ("walk");
} else if (grounded) {
animation.Play ("idle");
}
if (movement > 0) {
transform.rotation.y = 0;
transform.Translate (0, 0, movement/65);
} else if (movement < 0) {
transform.rotation.y = 180;
transform.Translate (0, 0, -movement/65);
}
if (grounded Input.GetButton("Jump")) {
rigidbody.AddForce (Vector3.up*200);
animation.Play ("jump");
grounded = false;
}
}
function OnCollisionEnter (c : Collision) {
if (c.transform.position.y < transform.position.y) {
grounded = true;
animation.Play ("idle");
}
}
It seems to me like the character thinks its not colliding with the level, so grounded is never changed to true.