PDA

View Full Version : stop physic


nlfrnassimi
03-10-2009, 01:39 AM
Hi,

I have created a simple bouncing ball. I want it to stop when it reaches a particular point. But I don't know how. I'll appreciate any help.

Here is my code for ball:


import viz

viz.go()

viz.phys.enable()

ground = viz.add('tut_ground.wrl') # Add ground
ground.collidePlane() # Make collideable plane
ball = viz.add('ball.wrl',pos=[0,.2,6]) # Add a ball
ballPhys = ball.collideSphere(bounce = 2) # Enable physics on ball
ball.applyForce([0,.3,.2],0.5) # Apply small force for half a second

Jeff
03-10-2009, 12:07 PM
You could use a timer and get the position of the ball. Once its position has reached the point you specify you can either disable physics for the scene
viz.phys.disable()
or for just the ball
ball.disable(viz.PHYSICS)

nlfrnassimi
03-10-2009, 06:25 PM
Can you please tell me how should I use the timer to get the ball position?

Thanks alot

Jeff
03-11-2009, 02:43 PM
When the z coordinate of the ball is greater than 10 it will stop
def stopball():

pos = ball.getPosition()
if pos[2] > 10:
ball.disable(viz.PHYSICS)


vizact.ontimer(0,stopball)

nlfrnassimi
03-11-2009, 08:26 PM
Thanks alot for your help:)