View Single Post
  #4  
Old 04-12-2016, 10:39 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,462
You can wait for a physics collision event within a task function. Here's an example:

Code:
import viz
import viztask

viz.go()

viz.clearcolor(viz.SLATE)

ground = viz.addChild('ground.osgb')
ground.collidePlane()

ball = viz.addChild('beachball.osgb',pos=[0,3,6])
ball.collideSphere()
ball.enable(viz.COLLIDE_NOTIFY)

def collideTask():
	
	# wait for spacebar to enable physics
	yield viztask.waitKeyDown(' ')
	viz.phys.enable()
	
	# wait for collision event
	d = yield viztask.waitEvent(viz.COLLIDE_BEGIN_EVENT)
	
	if d.data[0].obj1 == ball:
		collisionPoint = d.data[0].pos
		print 'the ball collided at',collisionPoint
	
	# wait 5 seconds
	yield viztask.waitTime(5)
	print '5 seconds elapsed'

viztask.schedule( collideTask() )
Or, from within the onCollide function, you could use vizact.ontimer2 to call default() after 5 seconds.
Reply With Quote