WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #29  
Old 03-01-2006, 01:50 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Hi,

That sounds fine. Here is really simple script that allows you to click an avatar. When it is clicked it will fall to the ground and disappear. Press the spacebar to bring the next available avatar back to life. What you want is something like the RemoveAvatar and RestoreAvatar functions. Instead of calling the function in response to a keyboard press you can call it in response to a stimuli or whatever you want. Let me know if this isn't what you wanted:
Code:
import viz
viz.go()

avatars = []
dead_list = []

#Create six avatars
for i in range(6):
	male = viz.add('male.cfg')
	male.translate(i,0,0)
	male.rotate(180,0,0)
	male.state(1)
	avatars.append(male) #Save avatar in list

def RemoveAvatar(avatar):
	avatar.visible(0) #Hide avatar
	avatar.speed(1) #Restore speed
	avatars.remove(avatar) #Remove from list
	dead_list.append(avatar) #Add to dead list

def RestoreAvatar():
	if len(dead_list):
		avatar = dead_list.pop() #Ressurrect dead avatar
		avatar.visible(1) #Make it visible
		avatars.append(avatar) #Add it to avatar list

def onmousedown(button):
	if button == viz.MOUSEBUTTON_LEFT:
		node = viz.pick() #Get object that was clicked
		if node in avatars: #Check if object is one of the avatars
			node.execute(7) #Execute the "shot" animation
			#Create action to wait for the animation duration then freeeze the avatar
			WaitThenFreeze = vizact.sequence( vizact.waittime(node.getduration(7)-0.2), vizact.speed_node(0) )
			node.add(WaitThenFreeze) #Add the action to the avatar
			RemoveAvatarAction = vizact.call(RemoveAvatar,node)
			node.add(RemoveAvatarAction) #Add action to remove avatar
viz.callback(viz.MOUSEDOWN_EVENT,onmousedown)

#Restore next available avatar
vizact.onkeydown(' ',RestoreAvatar)

#Move viewpoint so that all avatars are visible
viz.move(2.5,0,-10)

#Disable mouse navigation
viz.mouse(0)
Reply With Quote
 


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


All times are GMT -7. The time now is 10:51 PM.


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