How exactly does 'IsGrounded' work?
I've got a 3D player, and I want to use it in the animator. Currently I've put it in the animator trough a script, which work fine.
playerGrounded = KickStarter.player.IsGrounded();
anim.SetBool ("IsGrounded", playerGrounded);
But... Mid-air in the jump the bool suddenly turns on for 1 frame, then turns off again until the character hits the ground and then it stays off. Is this intentional? If so, what purpose does it serve? And if not, what could be wrong with my setup?
I'm having trouble getting my character to jump and fall correctly.
Is it possible to have a fall animation and temporarily turn root motion off? Or is that a bad solution?
Comments
But jumping/falling in AC does assume that motion is due to the Rigidbody, and not root motion. It may be that playing with the animation's import settings is enough to improve the motion without resorting to script.
Bear in mind, however, that Mecanim characters have a Vertical movement float parameter field - this is the recommended way of playing falling animations.
Let's see the way your components are set up. Screens of the Inspectors / Hierarchy and scene view would be great.
Try swapping around:
if (_rigidbody != null && Mathf.Abs (_rigidbody.velocity.y) > 0.1f)
{
return false;
}
if (_collider != null && _collider.enabled)
{
return Physics.CheckCapsule (transform.position + new Vector3 (0f, _collider.bounds.size.y, 0f), transform.position + new Vector3 (0f, _collider.bounds.size.x / 4f, 0f), _collider.bounds.size.x / 2f);
}
so that it instead reads:
if (_collider != null && _collider.enabled)
{
return Physics.CheckCapsule (transform.position + new Vector3 (0f, _collider.bounds.size.y, 0f), transform.position + new Vector3 (0f, _collider.bounds.size.x / 4f, 0f), _collider.bounds.size.x / 2f);
}
if (_rigidbody != null && Mathf.Abs (_rigidbody.velocity.y) > 0.1f)
{
return false;
}
Does that improve things?
What's the specific code you're changing? I'll consider adding it officially - but if not, it might be possible so simply make the function virtual so that a custom subclass can override it.
if (_collider != null && _collider.enabled)
{
return Physics.CheckCapsule (transform.position + new Vector3 (0f, _collider.bounds.size.y, 0f), transform.position + new Vector3 (0f, _collider.bounds.size.x / 4f, 0f), _collider.bounds.size.x / 2f, GetComponent<CharExtras>().groundLayerMask);
}
if (_rigidbody != null && Mathf.Abs (_rigidbody.velocity.y) > 0.1f)
{
return false;
}