WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 05-05-2009, 04:37 AM
Chrissy2009 Chrissy2009 is offline
Member
 
Join Date: May 2009
Posts: 33
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
Reply With Quote
  #2  
Old 05-05-2009, 11:24 AM
Moh200jo Moh200jo is offline
Member
 
Join Date: Feb 2009
Posts: 99
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!
Reply With Quote
  #3  
Old 05-06-2009, 02:09 PM
Chrissy2009 Chrissy2009 is offline
Member
 
Join Date: May 2009
Posts: 33
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 )
One ball pushes the other balls away. And the time, until all balls will slow down, I want to constrict to max. 5 seconds.
Reply With Quote
  #4  
Old 05-06-2009, 03:52 PM
Moh200jo Moh200jo is offline
Member
 
Join Date: Feb 2009
Posts: 99
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
this script could have what you are looking for
let me know if this helped you.

Last edited by Moh200jo; 05-06-2009 at 03:56 PM.
Reply With Quote
  #5  
Old 05-06-2009, 11:34 PM
Chrissy2009 Chrissy2009 is offline
Member
 
Join Date: May 2009
Posts: 33
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 )
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?
Reply With Quote
  #6  
Old 05-07-2009, 11:12 AM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,467
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])
Start a timer when when the force is applied that will expire after 3 seconds then call your function that stops the movement.
Reply With Quote
  #7  
Old 05-08-2009, 03:11 AM
Chrissy2009 Chrissy2009 is offline
Member
 
Join Date: May 2009
Posts: 33
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.
Reply With Quote
  #8  
Old 05-10-2009, 01:16 PM
Chrissy2009 Chrissy2009 is offline
Member
 
Join Date: May 2009
Posts: 33
Is there no idea to slow down the balls steadily?
Reply With Quote
  #9  
Old 05-10-2009, 02:47 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,467
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)
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

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


All times are GMT -7. The time now is 05:53 AM.


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