Why is my platformer collision slightly off?

I finally figured out how to do collisions, which I did in this project: (Snap! Build Your Own Blocks). But for some reason, the collisions are slightly off. The red square still collides, but sometimes there’ll be a gap between the two objects. Other times, it will hug the object perfectly.

Strangely, it seems to matter which side I approach from, despite the platform and player being perfectly square. Approaching from the left side yields the desired results, while all other sides have the unwanted gap (the right side most of all).

You bounce off the platform by gravity pixels. You have 1 chance out of 5 to not create a gap.
Furthermore, you may bounce step by step until you no longer touch the platform.