WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   how to have random animations play one after the other? (https://forum.worldviz.com/showthread.php?t=5572)

lklab 12-06-2015 02:39 PM

how to have random animations play one after the other?
 
Im trying to make an animated tree but I dont want the rustling to be too predictable. I was thinking of having a few "idle" animations that would randomly play one after the other. What would be the best way of doing this?

Also I need to be able to interrupt the looping idle animations to play a strong wing animation then go back to the loop.

currently I have this:
while(True):
print(count)
x = random.randint(0,3)

if(x==0):
tree3.state(1)
yield viztask.waitTime(2)
if(x==1):
tree3.state(1)
yield viztask.waitTime(2)
if(x==2):
tree3.state(5)
yield viztask.waitTime(2)
if(x==3):
tree3.state(6)
yield viztask.waitTime(2)

but this causes it to stutter since the animation changes in the middle of another.

using tree3.addAction(vizact.animation(3)) would solve this problem, but then I'm not able to play the stronger rustling animation.

mamort 12-06-2015 10:30 PM

A few questions to help understand what you are trying to achieve

1. Why not use the random number as animation state. e.g state(x) instead of if statements?
2. Why do you have waitTime calls, this is seen as bad practice in while loops and could be causing the stuttering?

I would approach as follows.

1. Use random number to assign animation e.g "tree.state(x)"
2. Use "viz.PATH_EVENT" to trigger next animation
3. Use .setPaused() to pause\resume for strong gust

Let me know if that suits\makes sense

lklab 12-10-2015 11:22 AM

yes, the waittime is likely what is causing the stutter, but without it the loop will continuously loop and either constantly adds animations to the queue (viz.addAction) or rapidly changes the animation without waiting for the current animation to end (.state(x)), which may drain resources.

the reason i didnt use tree.state(x) is because the animation numbers are not within the same range. But I could just choose a random number from a list and that could work too.

I tried to read into viz.pathevent, but that seems to work only for moving an object through a path, I just want to play a random animation built into the avatar.

So what I need is a loop that will finish an animation before playing the next one, but without adding 9 million items to the queue of animations. How would I have viz.pathevent know when the animation finished?

Erikvdb 12-11-2015 09:03 AM

Probably not the most elegant solution, but one that's short and working:
Code:

wind = False
tree.runAction(vizact.animation(1))

def onKeyDown(key):
    global wind
    if key == " ":
        wind = True
        tree.runAction(vizact.animation(3))

def onActionEnd(e):
    global wind
    if e.object is tree:
        if wind:
            wind = False
        else:
            anim = vizact.animation(random.choice([1,5,6]))
            tree.runAction(anim)

viz.callback(viz.ACTION_END_EVENT,onActionEnd)
viz.callback(viz.KEYDOWN_EVENT, onKeyDown)


mamort 12-11-2015 02:49 PM

Use Erikvdb code above to understand event based solution then take a look at the below references

".addEventAtEnd" animation path end event
"viz.ANIMATION_END_EVENT" avatar end event


All times are GMT -7. The time now is 08:13 PM.

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