PDA

View Full Version : Stop moving after few seconds??


Chrissy2009
05-05-2009, 04:37 AM
Hello all,

I'm trying to develop a application but now, I've got a problem:

I shoot a ball against other balls and then these balls collide. Like a billiard game. These balls are not on a table, they fly across the air. Therefore I set the gravity to [0,0,0].

This works very fine. But now the problem is that the balls are flying too long. It takes about 10 seconds till the balls stop moving. But I don't want to wait such a long time. The balls should stop moving after 3 seconds. Is this possible?

I searched the whole Vizard Documentation, but I can't find the relevant command.

I would be very pleased about every information and help.

Thanks a lot!
Chrissy

PS: Sorry for english mistakes

Moh200jo
05-05-2009, 11:24 AM
the sound like you have to use timer. Could you please looking at vizard functions because vizard has a timer function.
hope this helped you!

Chrissy2009
05-06-2009, 02:09 PM
But I only initiate the shoot. Afterwards the balls move automatically.

Where do I have to set the timer?

My code to initiate the shoot is:

vec.setLength(vizmat.Interpolate(1,400,power.get() ))
info.object.applyForce( vec, 1 )

One ball pushes the other balls away. And the time, until all balls will slow down, I want to constrict to max. 5 seconds.

Moh200jo
05-06-2009, 03:52 PM
to shoot balls each time, try to define a shooting function, may be something like thisdef shoot():
pass
.
.
vizact.ontimer(5,shoot)#each 5 sec
this script (http://www.worldviz.com/vizhelp/duckcourt.htm) could have what you are looking for
let me know if this helped you.

Chrissy2009
05-06-2009, 11:34 PM
Hi,

no - I don't think that's my problem.

Look. I've got one white ball and 14 other balls. Then I shoot the white ball against the other balls.


vec.setLength(vizmat.Interpolate(1,400,power.get() ))
info.object.applyForce( vec, 1 )

The white ball collides with the other balls and afterthat the other balls will fly across my room. I only initiate the shoot once!!

And now it takes about 20 seconds, until all balls will stop moving. And thats my problem.

Is there a command, like "stop moving all objects" or something like that?

Jeff
05-07-2009, 11:12 AM
You could loop through all your objects and set their velocities and angular velocities to zero.
for i in range (len(objects)):
objects[i].setVelocity([0,0,0])
objects[i].setAngularVelocity([0,0,0])
Start a timer when when the force is applied that will expire after 3 seconds then call your function that stops the movement.

Chrissy2009
05-08-2009, 03:11 AM
Hi Jeff,

thanks for your answer. This is exactly my problem. Great!

Is it possible to slow down the balls, so that they don't stop fitfully?

Thanks a lot.

Chrissy2009
05-10-2009, 01:16 PM
Is there no idea to slow down the balls steadily?

Jeff
05-10-2009, 02:47 PM
You could apply a small force opposite the direction the ball is moving. Here a function is called ten times, the first nine times getting the velocity of the ball and applying a small force opposite to it. On the tenth time the ball is stopped completely.
import viz
viz.go()
viz.phys.enable()

ground = viz.add('tut_ground.wrl')
ground.collidePlane()

ball = viz.add('ball.wrl', pos = [0,1,8])
ball.collideSphere()

ball.applyForce([2,0,10], .1)

num = 1
def slowBall():

global num

#slow down the ball
if num <10:
vx,vy,vz = ball.getVelocity()
ball.applyForce([-vx,-vy,-vz], .01)
num+=1

#stop the ball
else:
ball.setVelocity([0,0,0])
ball.setAngularVelocity([0,0,0])

#call function 10 times
vizact.ontimer2(.3,9, slowBall)