![]() |
|
#1
|
|||
|
|||
|
Stop moving after few seconds??
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 |
|
#2
|
|||
|
|||
|
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! |
|
#3
|
|||
|
|||
|
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: Code:
vec.setLength(vizmat.Interpolate(1,400,power.get())) info.object.applyForce( vec, 1 ) |
|
#4
|
|||
|
|||
|
to shoot balls each time, try to define a shooting function, may be something like this
HTML Code:
def shoot():
pass
.
.
vizact.ontimer(5,shoot)#each 5 sec
let me know if this helped you. Last edited by Moh200jo; 05-06-2009 at 03:56 PM. |
|
#5
|
|||
|
|||
|
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. Code:
vec.setLength(vizmat.Interpolate(1,400,power.get())) info.object.applyForce( vec, 1 ) 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? |
|
#6
|
|||
|
|||
|
You could loop through all your objects and set their velocities and angular velocities to zero.
Code:
for i in range (len(objects)): objects[i].setVelocity([0,0,0]) objects[i].setAngularVelocity([0,0,0]) |
|
#7
|
|||
|
|||
|
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. |
|
#8
|
|||
|
|||
|
Is there no idea to slow down the balls steadily?
|
|
#9
|
|||
|
|||
|
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.
Code:
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)
|
![]() |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to stop vizact.move | Jerry | Vizard | 3 | 06-04-2009 04:25 PM |
| moving and object by mouse but don't know how to stop the movement | nlfrnassimi | Vizard | 8 | 04-26-2009 07:23 AM |
| how can I stop an action? | nlfrnassimi | Vizard | 4 | 02-13-2009 12:59 AM |
| timer question | Elittdogg | Vizard | 5 | 10-10-2007 02:49 PM |
| moving viewpoint vs. translating Head_pos | bailenson | Vizard | 5 | 02-01-2005 01:51 PM |