In my project, the player has the ability to effectively wall slide. While a character is in contact with a wall, a frictional force is applied to combat the force of gravity. When one collider is involved, the wall slide works perfectly. However, when the character comes into contact with a second collider during a wall slide, it appears that either gravity begins pulling on the character less, or an upwards force is being applied from some unknown source. A link to a video portraying the issue can be found here.
As an additional note, all walls use the same collider with no physic material applied. The two walls shown in the example are lined up exactly and have the exact same width (check attached images). The relevant code can is here:
public void OnCollisionEnter2D(Collision2D collision)
{
Vector2 normal = collision.GetContact(0).normal;
SurfaceType surfaceType = Utilities.NormalToSurfaceType(normal, MaxFloorAngle);
if (collision.gameObject.layer == GameConstants.SurfaceLayer)
{
switch (surfaceType)
{
case SurfaceType.Floor:
Debug.Log("<color=cyan>Floor contact</color>");
IsGrounded = true;
break;
case SurfaceType.Wall:
Debug.Log("<color=yellow>Wall contact</color>");
wallContacts++;
if (!HasWallContact)
{
Debug.Log("<color=red>New wall contact</color>");
MitigateFallingForce();
WallJumpInfo = new WallJumpInfo(MovementData.wallJumpAngle, normal);
}
break;
}
recentContacts.Add(collision.gameObject, surfaceType);
}
}
public void OnCollisionStay2D(Collision2D collision)
{
if (HasWallContact)
ApplyWallSlideFrictionalForce();
}
private void ApplyWallSlideFrictionalForce()
{
Debug.Log($"Y velocity {rbody.velocity.y}");
if (rbody.velocity.y < 0)
{
float gravitationalForce = Physics2D.gravity.y * rbody.mass * rbody.gravityScale;
float frictionalForce = -gravitationalForce * MovementData.wallSlideFriction;
rbody.AddForce(Vector2.up * frictionalForce);
}
}