In order to get the bar and the ball to collide correctly you'll need to move the bar by applying a force or torque to it:
Code:
import viz
import vizact
viz.go()
viz.phys.enable()
bar = viz.add('box.wrl') # Add a box
bar.setScale(20,1,1) # Make it look more door like
shape = bar.collideBox() # Enable physics on the box
shape.setDensity(0.1)
ball = viz.add('ball.wrl')
ball.setScale([1.5,1.5,1.5])
ball.setPosition([0, 2, 0])
ballCollideShape = ball.collideSphere()
joint = viz.phys.addHingeJoint(bar,None,pos=[0,0,0],axis0=[0,0,1]) # Hinge joint attached to world
def push():
bar.applyTorque([0,0,20],duration=0.2)
vizact.onkeydown('1',push)
def pushBack():
bar.applyTorque([0,0,-20],duration=0.2)
vizact.onkeydown('2',pushBack)
def resetSimulation():
if ball.getPosition()[1] < -5:
ball.reset()
ball.setPosition([0, 2, 0])
bar.reset()
bar.setEuler([0,0,0])
vizact.ontimer(1,resetSimulation)
import vizcam
vizcam.PivotNavigate(center=[0,0,0],distance=30)