PDA

View Full Version : avatar animations


vduckie
09-13-2004, 05:24 PM
Hi,

I was using the avatar animations (for example, the sit and the shot) and the avatars always return to their original standing position after completing their animation. For example, if I use viz.act(sit) the avatar will sit down, then pop up back to their original standing position and stay there. If I use viz.state(sit) the avatar will sit down, return to their original position, and continue repeating this. How you you make the avatar sit down and stay there?

So whether I used viz.act or viz.state, I can't seem to get the avatar to do their action (sit or get shot) and then stay where they are (sitting or lying on the ground). How do you get them to stop returning to their original position every time?

Thanks.

farshizzo
09-14-2004, 09:36 AM
Hi,

Currently, the only way to do this is to use the avatar.speed command. When you set the speed of an avatar to 0, it will effectively freeze it.

I wrote a very short script that shows how to do this. Press the spacebar to activate the animation of the avatar being shot. Once the animation is activated, a timer will be set to expire when the animation is over. The timer will then freeze the avatar.import viz
viz.go()

FREEZE_AVATAR = 0

male = viz.add('male.cfg')
male.rotate(180,0,0)
viz.move(0,0,-8)

def onkeydown(key):
if key == ' ':
#Perform the action
male.act(7)
#Start a timer to freeze the avatar when the action is over
viz.starttimer(FREEZE_AVATAR,male.getduration(7))

viz.callback(viz.KEYDOWN_EVENT,onkeydown)


def ontimer(num):
if num == FREEZE_AVATAR:
#Freeze the avatar
male.speed(0)

viz.callback(viz.TIMER_EVENT,ontimer)Let me know if you need any more help

betancourtb82
02-15-2006, 05:45 PM
I tried running this piece of code and the avatar stood back up. Have you found any other methods of "freezing the avatar"? Also, I'm trying to run the animation of someone getting shot then laying on the ground. I'm not sure if that's different from the sit and shot animation.

Thank you,

farshizzo
02-15-2006, 06:06 PM
Hi,

Try replacing the starttimer code with the following instead:viz.starttimer(FREEZE_AVATAR,male.getdurat ion(7)-0.1)This will create a buffer zone to ensure the avatar is frozen before the animation fully completes. It should also work with your animation too.

betancourtb82
02-15-2006, 06:51 PM
Yes, I did viz.starttimer(FREEZE_AVATAR,(male.getduration(7)-.06).

By the way, how do you enter code into this forum? I'm sorry I'm asking so many questions, but you have been very helpful. I would like to show you the code I'm working on, but don't know how to format it.

Thanks

betancourtb82
02-15-2006, 06:56 PM
Nevermind that last question, I just figured it out. Now for my real question. The reason I'm writing this code is to create a scenario where someone falls when they get shot (i.e. a projectile hits the avatar, activated by a mouse click). I have modeled my code from the duckcourt demo but can't get the enemy to stay on the ground when shot. I'm thinking it has to do with the way the avatar is "viewed" by the program. I was wondering if you could help me figure out how to distinguish between each element in the array and denote who's getting shot. For now I would be happy just being able to click on the avatars in this code and have them fall and stay down. I think I can go from there. Thanks again



import viz

viz.go()
avatars = []
FREEZE_AVATAR = 0

#Go through a loop six times.
for i in range(4):
#Each time you go through the loop, create a new duck and
male = viz.add('male.cfg')
male.translate(-i, 0,10)
male.rotate(180,0,0)

#Add the new male to the "avatars" array.
avatars.append(male)


def onkeydown(key):
if key == 'r':
print 'R pressed'
# Kill timer FREEZE_AVATAR
viz.killtimer(FREEZE_AVATAR)
male.clear(viz.ALL)
male.clear(viz.CURRENT_ACTION)
male.state(1)

viz.callback(viz.KEYDOWN_EVENT,onkeydown)



def ontimer(num):
if num == FREEZE_AVATAR:
#Freeze the avatar
male.speed(0)


viz.callback(viz.TIMER_EVENT,ontimer)

def onmousedown(button):
#The mouse button 'button' is being pressed
if button == viz.MOUSEBUTTON_LEFT:
#Perform the action
male.act(7)
#Start a timer to freeze the avatar when the action is over
viz.starttimer(FREEZE_AVATAR,(male.getduration(7)-.07),1)
#male.act(8) pass

viz.callback(viz.MOUSEDOWN_EVENT,onmousedown)

viz.mouse(viz.OFF)

farshizzo
02-16-2006, 12:49 PM
Hi,

The code below will create six avatars and allow the user to click on any of them to cause them to fall down and stay down. Let me know if anything is unclear.import viz
viz.go()

avatars = []

#Create six avatars
for i in range(6):
male = viz.add('male.cfg')
male.translate(i,0,0)
male.rotate(180,0,0)
avatars.append(male) #Save avatar in 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)-.06), vizact.speed_node(0) )
node.add(WaitThenFreeze) #Add the action to the avatar
viz.callback(viz.MOUSEDOWN_EVENT,onmousedown)

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

#Disable mouse navigation
viz.mouse(0)

betancourtb82
02-17-2006, 01:36 PM
I have this bit of code that I am using from the duckcourt example. I can't find anything on the help that deals with collidesphere. Where did that come from and what does it mean.

Thanks

#Enable collisions with the ball based on a sphere shape
ball.collidesphere(0.25)
ball.isTarget = 0
collidables.append(ball)

farshizzo
02-17-2006, 03:04 PM
Hi,

The command tells Vizard to use a sphere with radius 0.25 when checking collisions with the objects using the collidingwith command. The collide functions are currently undocumented. Let me know if you want more information.

betancourtb82
02-24-2006, 02:16 PM
I was wondering if you could help me out. I'm trying to add an animation where, if I click on an avatar, it falls to the ground and disappears. I got the falling part down, but I added the fadeReset sequence to try and delay the disappearing and it doesn't work out. Any ideas?

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.clear(viz.ALL)
node.clear(viz.CURRENT_ACTION)
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)-.139), vizact.speed_node(0))
fadeReset = vizact.sequence(vizact.waittime(5),node.remove())
#vizact.sequence(vizact.waittime(2),avatars.remove (male),1)
node.add(WaitThenFreeze) #Add the action to the avatar
node.add(fadeReset)

farshizzo
02-24-2006, 03:09 PM
Hi,

The problem is that you are calling node.remove(). This function will immediately delete the object. In this example you need to create an action that will remove the node. Use the following code instead:fadeReset = vizact.sequence(vizact.waittime(5),vizact.call(nod e.remove))The vizact.call action will simply call the function that you pass to it.

betancourtb82
02-27-2006, 02:00 PM
I think it's working out but I do get some traceback errors. Here is the code:def onmousedown(button):
global i
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.clear(viz.ALL)
node.clear(viz.CURRENT_ACTION)
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)-.14), vizact.speed_node(0))
#vizact.sequence(vizact.waittime(2),avatars.remove (male),1)
node.clear(viz.ALL)
node.clear(viz.CURRENT_ACTION)
node.add(WaitThenFreeze) #Add the action to the avatar
node.clear(viz.ALL)
node.clear(viz.CURRENT_ACTION)
fadeReset = vizact.sequence(vizact.waittime(1),vizact.call(nod e.remove))
node.add(fadeReset)
i = 2;


Here are the traceback errors. I'm not sure what they all mean.

Traceback (most recent call last):
File "C:\Program Files\Vizard25\viz.py", line 5916, in mytimer
curAction.update(elaps,curAction._obj_)
File "C:\Program Files\Vizard25\vizact.py", line 653, in update
self.checkaction(object)
File "C:\Program Files\Vizard25\vizact.py", line 629, in checkaction
__endAction__(object,self.curAction)
File "C:\Program Files\Vizard25\vizact.py", line 219, in __endAction__
object._action.notifyEndAction(action._obj_,action ._actiondata_.callbackData,action._pool_)
AttributeError: 'int' object has no attribute 'notifyEndAction'

farshizzo
02-27-2006, 02:32 PM
Hi,

Try the following instead:node.add(vizact.waittime(1))
node.add(vizact.call(node.remove))