WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   stop physic (https://forum.worldviz.com/showthread.php?t=1892)

nlfrnassimi 03-10-2009 01:39 AM

stop physic
 
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
Code:

viz.phys.disable()
or for just the ball
Code:

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
Code:

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:)


All times are GMT -7. The time now is 11:19 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC