PDA

View Full Version : Avatars in an array and link/unlink


betancourtb82
08-23-2006, 12:45 PM
I was wondering if I can get some assistance on this. I created a program that introduces 3 avatars to a user. The user then shoots the avatar by clicking on the avatar that his "holding" a weapon. The 3 avatars can have either a gun in hand, a cell phone in hand or a camera around his/her neck.

Once an avatar is shot, the avatar is supposed to unlink with the object and come back w/ another object. The problem i'm having is that only the last avatar is working. I've tried changing which avatar is last and removing an avatar, leaving only 1 or 2, and what i've noticed is that anytime i remove or change the avatar order, only the last avatar functions correctly. I've gone over the code many times and can't figure out the problem. PLEASE HELP. I've included the relavent parts of the code for your reference.

To get the weapons:
def GetWeapon(avatar,number):
global link, objectlink
if number == 0:
#weapons to use
objectlink = viz.add(viz.GROUP) #for gun
gun = objectlink.add('M16M203.WRL')
avatar.gun = gun
gun.scale(.0005,.0005,.0005)
objectlink.link(hand)
elif number == 1:
objectlink = viz.add(viz.GROUP) #for phone
phone = objectlink.add('C:\Program Files\Vizard25\resources/phone.3ds')
#avatar.phone = phone
phone.scale(1.5,1.5,1.5)
phone.rotate(-90,0,-90)
phone.translate(0,0.03,0.02)
objectlink.link(hand)
else:
objectlink = viz.add(viz.GROUP) #for camera
camera = objectlink.add('camera.WRL')
#avatar.camera = camera
camera.scale(.0005,.0005,.0005)
camera.translate(0,-.25,.17)
camera.rotate(180)
objectlink.link(neck)

To initialize the avatars:
for x in range(0,3):
if x == 0:
male = viz.add(people[x])
male.scale(.11,.11,.11)
# male.face(faces[0])
hand = male.getbone('skel_HandRF')
neck = male.getbone('skel_Neck')
GetWeapon(male,0)
#phonelink.link(hand)
male.tag = 0
male.threatening = TRUE
male.appearance = 0
male.facepic = 0
elif x == 1:
male = viz.add(people[1])
male.scale(.11,.11,.11)
# male.visible(0,'gz_mstky_headlat.cmf')
# male.face(faces[2])
hand = male.getbone('skel_HandRF')
neck = male.getbone('skel_Neck')
GetWeapon(male,1)
#cameralink.link(neck)
male.tag = 1
male.threatening = FALSE
male.appearance = 0
male.facepic = 0
elif x ==2:
male = viz.add(people[0])
male.scale(.11,.11,.11)
male.visible(0,'gz_mave_headwht.cmf')
male.face(faces[0])
hand = male.getbone('skel_HandRF')
neck = male.getbone('skel_Neck')
GetWeapon(male,2)
#gunlink.link(hand)
#male.face(faces[1])
male.tag = 2
male.threatening = FALSE
male.appearance = 0
male.facepic = 0
male.translate(3*x,-10,10)
male.rotate(180)
#Add the avatar to the waiting and lemming list
waitlist.append(male)
characters.append(male)

To remove and restore the avatars (w/unlink and link)
def RemoveAvatar(avatar):
global avatarCount, objectlink
avatar.visible(0) #Hide avatar
avatar.speed(1) #Restore speed
# THIS ONE MIGHT WORK!
# objectlink.unlink()
objectlink.translate(0,0,10)
characters.remove(avatar) #Remove from list
dead_list.append(avatar) #Add to dead list
# objectlink.unlink()
# GetWeapon(deadlist[0],weaponchoice)
avatarCount += 1
print 'avatar count is: ', avatarCount
def RestoreAvatar():
global keyindex, weaponchoice, objectlink
objectlink.unlink()
if weaponchoice > 3:
weaponchoice = 0
print 'weapon choice is',weaponchoice
if len(dead_list):
print "avatar restored"
avatar = dead_list.pop() #Ressurrect dead avatar
weaponchoice += 1
GetWeapon(avatar,weaponchoice)
avatar.visible(1) #Make it visible
characters.append(avatar) #Add it to avatar list

When the avatars are shot:
def MoveBullet(bullet,elapsed):
global avatarsHit, autospawn, soldierCount, maleCount, femaleCount, threatCount, nonthreatCount
#get the bullet's current position
pos = bullet.get(viz.POSITION)

#calculate the balls future position based on it's velocity
futurePos = pos + (bullet.vector * elapsed)

#Check if bullet intersected with anything
info = viz.intersect(pos,futurePos)
if info.intersected:
if info.object in characters:
info.object.disable(viz.COLLISION)
#print "in characters"
if info.object.tag == 0:
soldierCount += 1
if info.object.threatening == TRUE:
threatCount += 1
elif info.threatening == FALSE:
nonthreatCount += 1
elif info.object.tag == 1:
maleCount += 1
if info.object.threatening == TRUE:
threatCount += 1
elif info.object.threatening == FALSE:
nonthreatCount += 1
elif info.object.tag == 2:
femaleCount += 1
if info.object.threatening == TRUE:
threatCount += 1
elif info.object.threatening == FALSE:
nonthreatCount += 1
avatarsHit = avatarsHit + 1
viz.playsound('arrgh.wav')
WaitThenFreeze = vizact.sequence( vizact.waittime(info.object.getduration(6)-.85), vizact.speed_node(0) )
info.object.execute(6)
info.object.clear(viz.ALL)
info.object.clear(viz.CURRENT_ACTION)
info.object.add(WaitThenFreeze) #Add the action to the avatar
RemoveAvatarAction = vizact.call(RemoveAvatar,info.object)
info.object.add(RemoveAvatarAction) #Add action to remove avatar
bullet.visible(0)
bullet.active = 0
#Update balls positions
bullet.translate(futurePos.get())

betancourtb82
08-29-2006, 12:14 PM
I posted this last week and still have not received a response. Please help. I have to get this done sometime this week and I would appreciate the help. If it would help, I can include the code for the entire program.

Thank you

tobin
08-29-2006, 03:40 PM
At a quick glance the code looks sound. Can you send as concise a copy as possbile of the simulation that replicates this problem to support@worldviz.com and maybe we can find out what's wrong?

Gladsomebeast
09-01-2006, 02:44 PM
Just a guess: Somewhere along the line you are using the same global varable to hold the link/gun/avatar/whatever object. So when you setting up the avatars you are overwriting references to the link/whatever objects you need. Keep these things assoated with the avatars you create.


#Setting up avatar
avatar1.currentWeapon = avatar1.getChild("hand").add( 'gun.wrl')
.
.
.
#Swap in new weapon
tempWeapon = avatar1.currentWeapon
avatar1.currentWeapon = sidelinedWeapon
sidelinedWeapon = tempWeapon

avatar1.currentWeapon.parent( avatar1.getChild("hand") )
avatar1.currentWeapon.visible( viz.ON )

sidelinedWeapon.visible( viz.OFF )

betancourtb82
09-05-2006, 12:15 PM
That sounds like that might work, however, I'm having a hard time finding the child object for hand and neck. I know you can't just put hand and neck, but I'm not sure where to find what the actual name of the child objects are. The avatar file is above the 1.0MB limit, therefore I cannot attach it as a reference. I did try to right-click on the the avatar in the resources window, but no properties came up.

Gladsomebeast
09-05-2006, 12:59 PM
There should be a plus icon next to the avatar in the resources window. Expand that to show bones icon which then has a list of avatar bones

betancourtb82
09-05-2006, 01:04 PM
I did that. For this avatar, the hand is named skel_HandRF (for right hand finger). I used the following code. I received the following errors:
** ERROR: Could not find child with name 'skel_HandRF'
** ERROR: Could not find child with name 'skel_HandRF'
** ERROR: Could not find child with name 'skel_Neck'


for x in range(0,3):
if x == 0:
male = viz.add(people[2])
male.scale(.11,.11,.11)
# GetWeapon(male,0)
male.currentWeapon = male.getchild('skel_HandRF').add("M16M203.WRL")
male.tag = 0
male.threatening = TRUE
male.appearance = 0
male.facepic = 0
elif x == 1:
male = viz.add(people[1])
male.scale(.11,.11,.11)
male.currentWeapon = male.getchild('skel_HandRF').add("C:\Program Files\Vizard25\resources/phone.3ds")
# GetWeapon(male,1)
male.tag = 1
male.threatening = FALSE
male.appearance = 0
male.facepic = 0
elif x ==2:
male = viz.add(people[0])
male.scale(.11,.11,.11)
male.visible(0,'gz_mave_headwht.cmf')
male.face(faces[0])
# GetWeapon(male,2)
male.currentWeapon = male.getchild('skel_Neck').add("camera.WRL")
male.tag = 2
male.threatening = FALSE
male.appearance = 0
male.facepic = 0
male.translate(3*x,-10,10)
male.rotate(180)
#Add the avatar to the waiting and lemming list
waitlist.append(male)
characters.append(male)

Gladsomebeast
09-05-2006, 04:06 PM
To get a bone, use the <VizAvatar>.getbone() fucntion, not getchild.