I'm working on a Unity game where the player shoots on cubes to change their weight (it can be positive or negative, last one meaning 'falling' to the roof) and i'm experiencing a problem with rigidbodies, spherecasting and detecting if the player is grounded or not.
When my player is on the ground or on top of any object with a collider, I detect it as 'grounded' using the following function:
if (Physics.SphereCast(transform.position, m_Capsule.radius, Vector3.down, out hitInfo,
((m_Capsule.height / 2f) - m_Capsule.radius) + advancedSettings.groundRoofCheckDistance, Physics.AllLayers, QueryTriggerInteraction.Ignore))
{
m_IsGrounded = true;
}
where advancedSettings.groundRoofCheckDistance
is set to 0.01f.
Until there, everything works fine. But now, when I try to get on top of a cube with a non-kinematic rigidbody, I can't get that boolean to be true.
Here are two captures to illustrate my problem :
In this one, the player is falling on a non-kinematic rigidbody box and the boolean circled in red is m_isGrounded (false):
And here, same but the cube is kinematic and the ground is detected just fine:
I really can't figure out why the rigidbodies do that, or if I have a problem with my ground detection function, so any help is welcome. Thanks!
PS: I'm using Unity 2018.2.15f1