|
|
Thread Tools | Rate Thread | Display Modes |
#1
|
|||
|
|||
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()
#Change navigation style to pivot
cam = vizcam.PivotNavigate(center=[0,0,0], distance = 15)
cam.rotateUp(45)
cam.rotateRight(0)
#Add the object that will do the grabbing
hand = viz.addChild( 'marker.wrl' )
hand.setPosition( [-0.5, 1.8, 2.5] )
viz.phys.setGravity(0,-9.8/6,0) #Half Gravity
ground = viz.add('tut_ground.wrl') # Add ground
ground.collidePlane() # Make collideable plane
logo = viz.add('logo.wrl',pos=[0,1,6]) # Add logo
logo.collideMesh(bounce=1.5) # Collide and make it bounce a bit
link = None #The handle to the link object
for x in range(10):
for z in range(10):
ball = viz.add('white_ball.wrl',pos=[-.5+.1*x,2.5+.1*z,6],scale=[.5,.5,.5])
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
def toggleLink():
global link
if link:
#If link exits, stop grabbing
link.remove()
link = None
else:
#If no link, grab the ball with the hand
link = viz.grab(hand, x)
vizact.onkeydown(' ',toggleLink)
#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)
Thanks for your time! |
#2
|
|||
|
|||
I see the ring question has been answered here.
However, I would still benefit from someone helping with my first question. How do I get rid of initial "bounce" and "wobble" of a node? Here's another example to demonstrate my question: If I have a ball sitting atop a hole which is slightly smaller than the diameter of the ball, and gravity or a force is enabled, my ball doesn't "sit still" atop the hole. Rather, it wobbles around the hole for several seconds until it eventually slows down and sits atop the hole. If the collision plane and ball is perpendicular to gravity, shouldn't the ball's position remain initially constant and not wobble around? My attached pictures shows one of the balls wobbling around the hole instead of its position remaining constant. Code:
viz.add('shaft.dae', pos = (0,0,0))
base = viz.add('base.dae', scale=[1,1,1],euler=[0,0,0], pos = (-2.5,0,-2))
base.texture(pic_base)
# add spheres
sphere1 = viz.addChild('ball.dae', viz.WORLD, pos = (-.65,.17,.84), scale=[0.4,0.4,0.4],euler=[0,0,0], texture=(pic_sphere))
sphere2 = viz.addChild('ball.dae', viz.WORLD, pos = (-.65,.2,-.19), scale=[0.4,0.4,0.4],euler=[0,0,0], texture=(pic_sphere))
sphere3 = viz.addChild('ball.dae', viz.WORLD, pos = (-.65,.2,-1.18), scale=[0.4,0.4,0.4],euler=[0,0,0], texture=(pic_sphere))
sphere4 = viz.addChild('ball.dae', viz.WORLD, pos = (-1.64,.2,.82), scale=[0.4,0.4,0.4],euler=[0,0,0], texture=(pic_sphere))
sphere5 = viz.addChild('ball.dae',viz.WORLD, pos = (-1.64,.2,-.19), scale=[0.4,0.4,0.4],euler=[0,0,0], texture=(pic_sphere))
sphere6 = viz.addChild('ball.dae', viz.WORLD, pos = (-1.64,.2,-1.18), scale=[0.4,0.4,0.4],euler=[0,0,0], texture=(pic_sphere))
base.collideMesh()
viz.phys.setGravity(0,-10,0) #world gravity
sphere1.collideSphere(bounce = 0)
#sphere1.applyForce([0,0,-2])
#ringPhys = sphere2.collideSphere(bounce = 0)
#ringPhys = sphere3.collideSphere(bounce = 0)
#ringPhys = sphere4.collideSphere(bounce = 0)
#ringPhys = sphere5.collideSphere(bounce = 0)
#ringPhys = sphere6.collideSphere(bounce = 0)
#linking
link = None #The handle to the link object
#Grab or let go of the ring
def toggleLink():
global link
if link:
#If link exits, stop grabbing
link.remove()
link = None
else:
#If no link, grab the circle with the shaft(parent + grasper tip (children))
link = viz.grab(shaft, sphere1)
vizact.onkeydown(' ',toggleLink)
vizact.whilekeydown(viz.KEY_UP,shaft.setPosition,[0,vizact.elapsed(1),0],viz.REL_PARENT)
vizact.whilekeydown(viz.KEY_DOWN,shaft.setPosition,[0,vizact.elapsed(-1),0],viz.REL_PARENT)
vizact.whilekeydown(viz.KEY_RIGHT,shaft.setPosition,[vizact.elapsed(1),0,0],viz.REL_PARENT)
vizact.whilekeydown(viz.KEY_LEFT,shaft.setPosition,[vizact.elapsed(-1),0,0],viz.REL_PARENT)
|
#3
|
|||
|
|||
If modifying the physics properties of the object is not working the way you expect, you could try removing all forces on the ball once it reaches a certain position. To do that, use the node3d.reset command.
|
#4
|
|||
|
|||
Jeff, thanks for your reply.
I think I found the problem (for the 2nd example) was because the ball's center was at (0,0,0) and the position was initially (0,0,0) as well. Therefore, the ball was initially colliding with the ground and thus it pops or bounces up. If I moved the initial position to (0,.25,0), then I didn't notice a bounce. Thanks again! |
Thread Tools | |
Display Modes | Rate This Thread |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
collision with physics enabled | joeymax | Vizard | 2 | 04-17-2008 02:49 PM |