View Single Post
#1
10-31-2012, 10:29 AM
 mhead10 Member Join Date: Mar 2012 Posts: 40
Physics: Ball Bounces Unexpectly Based Upon Size + Ring Collision Shape

I have modified an example physics script to try and determine why my script isn't working. I want my "ball.wrl" to remain stationary on the ground (as it would in real life because gravity keeps it on the ground). However, this only seems to work if the ball scale is very small (0.1,0.1,0.1) versus large (10,10,10). If the scale is large, the ball takes an initial bounce and then remains stationary. I've set ball bounce equal to zero, so I'm not sure why the ball bounces. (I realize the "bounce" effect scales with size, but I would like to get rid of the initial effect from the beginning).

Code:
```#meshing
import viz
import vizact
import vizcam
viz.phys.enable()   # Enable physics

viz.setMultiSample(4)
viz.fov(60)
viz.go()

cam = vizcam.PivotNavigate(center=[0,0,0], distance = 15)
cam.rotateUp(45)
cam.rotateRight(0)

#Add the object that will do the grabbing
hand.setPosition( [-0.5, 1.8, 2.5] )

viz.phys.setGravity(0,-9.8/6,0) #Half Gravity
ground.collidePlane()   # Make collideable plane

logo.collideMesh(bounce=1.5) # Collide and make it bounce a bit

for x in range(10):
for z in range(10):
ball.collideSphere()

x = viz.add('ball.wrl', pos =(0,0,0), scale=[1,1,1])
ringPhys = x.collideSphere(bounce = 0)   # Define x's physical properties

#Grab or let go of the ball
else:
#If no link, grab the ball with the hand

#Setup keyboard control of hand and ball
vizact.whilekeydown(viz.KEY_UP,hand.setPosition,[0,vizact.elapsed(1),0],viz.REL_PARENT)
vizact.whilekeydown(viz.KEY_DOWN,hand.setPosition,[0,vizact.elapsed(-1),0],viz.REL_PARENT)
vizact.whilekeydown(viz.KEY_RIGHT,hand.setPosition,[vizact.elapsed(1),0,0],viz.REL_PARENT)
vizact.whilekeydown(viz.KEY_LEFT,hand.setPosition,[vizact.elapsed(-1),0,0],viz.REL_PARENT)

vizact.whilekeydown('w',hand.setEuler,[vizact.elapsed(90),0,0],viz.REL_PARENT)
vizact.whilekeydown('s',hand.setEuler,[vizact.elapsed(-90),0,0],viz.REL_PARENT)
vizact.whilekeydown('d',hand.setEuler,[0,vizact.elapsed(90),0],viz.REL_PARENT)
vizact.whilekeydown('a',hand.setEuler,[0,vizact.elapsed(-90),0],viz.REL_PARENT)```
Secondly, if I change the ball collision shape to mesh, gravity no longer affects the ball. I'm guessing the documentation is defining gravity as a force (link), "Collide mesh objects are unaffected by forces and can only provide a solid collision area for other objects." Therefore, is there a way I can have a ring shape (just like a wedding ring) be a collision shape and be affected by gravity. I need to have the ring be dropped around a peg (capsule collision shape or mesh of cylinders) without having the ring go through the peg (only around it).