Hey! When implementing a drop down behavior from floating platforms, I run into an issue with collision (I think). When a drop down sequence is initiated, Player’s layer collision with the layer for these platforms is disabled momentarily or until the given input is released. If this release happens too fast, the collision is re-enabled while the character’s collider is within the platform collider, causing weird behavior. Namely, if the majority of the character is above the collider, it gets “sprung back” into starting position.
I tried working around it in two main ways: 1) adding a timer after release, which keeps the collision disabled longer, so the character has a chance to pass low enough to avoid the “spring back”, and 2) applying some additional downward force in the moment of initiating the drop. Together, these somewhat alleviate the issue, but introduce other problems. The timer can’t be too short to work and too long to allow passing through lower platforms if the player doesn’t want to, and the downward force can be only so strong before it starts looking unnatural.
In tutorials and guides I’ve looked into, they don’t really deal with this issue. Also, these floating platforms have a PlatformEffector2D and a PolygonCollider2D components.
My main question is: is there a way to prevent this behavior? Or is there some better approach to dropping down from platforms? Thanks!
My dropping down code:
void DropDown()
{
if (movementInputVert < 0)
{
Physics2D.IgnoreLayerCollision(
LayerMask.NameToLayer("Player"),
LayerMask.NameToLayer("OneWayPlatform"),
true
);
dropDownResetTimer = dropDownResetTimerLimit;
return;
}
else if (dropDownResetTimer <= 0)
{
Physics2D.IgnoreLayerCollision(
LayerMask.NameToLayer("Player"),
LayerMask.NameToLayer("OneWayPlatform"),
false
);
return;
}
dropDownResetTimer -= Time.fixedDeltaTime;
}