Question by
Tona999 · Feb 05, 2021 at 09:13 PM ·
rigidbody2dcollision2dinterpolationground detectionoverlapping
Collision Detection on Rb with Interpolation and Rb with Extrapolation does not work the same way.
Hi, I am using the following approach to get the player grounded:
Grounding:
void OnCollisionEnter2D(Collision2D col)
{
if (!Grounded && col.enabled) // get grounded only if collision is enabled
Grounded = true;
}
Ungrounding:
float Radius = 1.4f;
void FixedUpdate() {
Collider2D[] cols = Physics2D.OverlapCircleAll(transform.position, Radius, GroundLayer);
if (Grounded && cols.Length == 0)
Grounded = false;
}
This works very well if its Rigidbody interpolation is set to "Extrapolate", but does not always work if it's set to "Interpolate" (it does work most of the time). I've tried both Continuous and Discrete collision detection.
This approach allows for a small margin of movement where the player doesn't get ungrounded even though it's not colliding with anything in that particular moment.
I can not use the OverlapCircleAll()
method for grounding because I need to get grounded only if the collision is enabled (I have some platforms and don't want to get grounded when coming from the bottom).
Any ideas on how to make it work? Thanks!
Comment