Setup an inverted pendulum simulation with BGE
I made a simple example in the game engine of a mouse controlled inverted pendulum. It answers only your question about the hinge, but maybe you can go from there.

The body block has a rigid body constraint, type hinge, target is the pole. The weight at the top is parented to the pole.

I'm sure it's not physically correct, but I had to change translation and rotation damping in the physics properties of the pole to have a chance at controlling the pendulum. I also reduced the mass of the pole.

If you'd like to have a look, here's the blend file: