Example: constructing an hourglass with physics

Like sand through an hourglass... So are the days of our lives.

I made this to help with another post, but though I'd share the complete version. The general goal was to make an hourglass with Hype's physics that supports rotation of the hour glass.

The main points to get this working are:

  • The hour glass itself is drawn separate of of the physics bodies that make its boundaries.
  • While you could do the hour glass any number of way (like an image), I made the hour glass itself as a vector shape representing a quarter of the shape, and then used symbols to duplicate the other quarters and used 3D rotation to flip them all to make the whole body. I then grouped them together.
  • I made a little rectangle that represents the center of the hour glass for visual reference later.
  • The boundaries need to be made from rectangles or convex vector shapes. I wound up using two rectangles for the top and bottom, and vector shapes for the sides.
  • The boundaries should be pretty thick to prevent the physics engine from accidentally ejecting the bodies for the sand
  • The boundaries should not be rotated as a group. Instead you should hold down the command key to move the transform origin to the exact center of the hourglass -- the same spot you marked with the rectangle earlier.
  • The boundaries should be static physics bodies
  • The sand should be non-overlapping ellipses that are dynamic physics bodies. I recommend reducing the bounce factor.
  • I animated rotation for the boundaries and hour glass together for the flip
  • I then used opacity to make the boundaries hidden

Hour Glass.hype.zip (73.4 KB)