View Single Post
  #2  
Old 03-14-2013, 06:04 AM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,466
In the following example the spacebar is used to start and stop the avatar as he walks between two points:
Code:
import viz
import viztask
import vizact
viz.go()

viz.add('ground.osgb')
avatar = viz.addAvatar('vcc_male2.cfg',pos=[0,0,9])
avatar.state(1)

walkLeft = vizact.walkTo([2.5,0,9])
walkRight = vizact.walkTo([-2.5,0,9])
walkActions = viz.cycle([walkLeft,walkRight])

waitSpaceBar = viztask.waitKeyDown(' ')
waitLeft = viztask.waitActionEnd(avatar,walkLeft)
waitRight = viztask.waitActionEnd(avatar,walkRight)
waitActions = viz.cycle([waitLeft,waitRight])

def walkAndStopTask():
	yield waitSpaceBar
	while True:
		condition = waitSpaceBar
		walkAction = walkActions.next()
		waitAction = waitActions.next()
		while condition == waitSpaceBar:
			avatar.runAction(walkAction)
			d = yield viztask.waitAny([waitSpaceBar,waitAction])
			condition = d.condition
			if condition == waitSpaceBar:
				avatar.clearActions()
				yield waitSpaceBar
			
viztask.schedule(walkAndStopTask())

Last edited by Jeff; 03-14-2013 at 07:08 AM.
Reply With Quote