Ok, everything works great so far. The only problem is that I am getting some kind of traceback error.
Code:
Traceback (most recent call last):
File "Test2WithEyeAdjustment.py", line 185, in mytimer
avatar = avatars[nextAvatar]
IndexError: list index out of range
This occurs whenever I shoot an avatar and he disappears. When I double click on the error it highlights:
Code:
def mytimer(num):
global avatars
if num == ANIMATION:
#Calculate elapsed time since last update
elapsed = viz.elapsed()
#Update each active ball
for bullet in bullets:
if bullet.active:
#Move the ball and check if it has collided with any objects
MoveBullet(bullet,elapsed)
elif num == START_AVATAR:
global nextAvatar
#Get the next available avatar and start it
avatar = avatars[nextAvatar]
#favatar = favatars[nextAvatar]
walkAvatar(avatar)
#walkAvatar(favatar)
nextAvatar = (nextAvatar + 1) % NUM_AVATARS
viz.starttimer(START_AVATAR,TIME_BETWEEN_AVATARS)
#Create callbacks for timer events
viz.callback(viz.TIMER_EVENT,mytimer)
When I shoot the avatars, this function is called:
Code:
def shootBullet():
global nextBullet
#find the next available ball to shoot
bullet = bullets[nextBullet]
nextBullet = (nextBullet + 1) % NUM_BULLETS
#Calculate the vector of the ball based on the mouse position
pos = viz.mousepos()
bulletvector = viz.screentoworld(pos[0]+0.25,pos[1]) #Need to account for stereo
bullet.vector = viz.Vector(bulletvector[3]-bulletvector[0],bulletvector[4]-bulletvector[1],bulletvector[5]-bulletvector[2])
bullet.vector.normalize()
bullet.vector *= BULLET_SPEED
#translate the bullet to the head position
bullet.translate(viz.get(viz.HEAD_POS))
#make the bullet visible
bullet.visible(viz.ON)
#mark the bullet as active
bullet.active = 1
def MoveBullet(bullet,elapsed):
#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 avatars:
#viz.starttimer(FREEZE_AVATAR,info.object.getduration(7)-0.1)
WaitThenFreeze = vizact.sequence( vizact.waittime(info.object.getduration(7)-0.05), vizact.speed_node(0) )
info.object.execute(7)
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())
#Shoot a ball whenever left mousebutton is clicked
vizact.onmousedown(viz.MOUSEBUTTON_LEFT,shootBullet)
What does the error mean? Can it be fixed