![]() |
|
#1
|
|||
|
|||
Hi,
I'm still not clear on what you are trying to accomplish. Calling object.remove() will permanently remove the object. Once it is removed you can't use it anymore. If you only plan on having 4 avatars at a time, I suggest you add them all at the beginning of your script. Then instead of removing them permanently, just make them invisible. Then when you want to reuse them later on make them visible again. I would provide sample code if you explained exactly what you want to do. |
#2
|
|||
|
|||
Ok, what happens is that this is a shooting scenario where the subject is presented with a new avatar every certain interval of time (say 2 seconds). Currently, this occurs until 4 avatars have appeared. Now, each time a user shoots an avatar, I would like for the avatar to fall, disappear, and be ready to restart from the original position. We have not decided whether this should happen automatically or if they should re-appear after a stimulus (say keyboard entry). We are leaning towards the re-appearing happening automatically. I thought I would have to remove the avatar from the array and re-append him after he was removed. Am I looking at this the wrong way?
|
#3
|
|||
|
|||
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) |
#4
|
|||
|
|||
Works great. I did however want to ask you, is there a way to say "if the number of avatars does not equal 4, restore the avatar. I tried using
Code:
#Restore next available avatar vizact.sequence(vizact.waittime(4),RestoreAvatar) #instead of using onkeydown #vizact.onkeydown(' ',RestoreAvatar) |
![]() |
Thread Tools | |
Display Modes | Rate This Thread |
|
|