/// <summary> /// Evalutates a collision for wall, floor and ceiling contacts. /// </summary> public void EvaluateCollision(PlayerController p, Collision2D collision) { for (var i = 0; i < collision.contactCount; i++) { var normal = collision.GetContact(i).normal; var surface = collision.gameObject.GetComponent <Surface>() ?? p.DefaultSurface; if (surface.IgnoreContacts) { continue; } // Floor if (normal.y > FloorThreshold) { var angle = p.GripToFallAngle(surface.Grip); var threshold = Mathf.Cos(angle * Mathf.Deg2Rad); if (normal.y >= threshold) { StableGroundContactCount++; StableSurfaceNormal += normal; StableSlopeAngleThreshold += angle; } else { UnstableGroundContactCount++; UnstableSurfaceNormal += normal; UnstableSlopeAngleThreshold += angle; } continue; } // Wall if (normal.y <= FloorThreshold && normal.y >= CeilThreshold) { WallContactCount++; WallNormal += normal; continue; } // Ceiling //if (normal.y < CeilThreshold) //{ //continue; //} } }