WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Thread Tools Rate Thread Display Modes
Old 12-06-2015, 02:39 PM
lklab lklab is offline
Join Date: Mar 2015
Posts: 20
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:
x = random.randint(0,3)

yield viztask.waitTime(2)
yield viztask.waitTime(2)
yield viztask.waitTime(2)
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.
Reply With Quote
Old 12-06-2015, 10:30 PM
mamort mamort is offline
Join Date: Jun 2015
Posts: 18
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 <animationpath>.setPaused() to pause\resume for strong gust

Let me know if that suits\makes sense
Reply With Quote
Old 12-10-2015, 11:22 AM
lklab lklab is offline
Join Date: Mar 2015
Posts: 20
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?
Reply With Quote
Old 12-11-2015, 09:03 AM
Erikvdb Erikvdb is offline
Join Date: May 2013
Posts: 63
Probably not the most elegant solution, but one that's short and working:
wind = False

def onKeyDown(key):
    global wind
    if key == " ":
        wind = True

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

viz.callback(viz.KEYDOWN_EVENT, onKeyDown)
Reply With Quote
Old 12-11-2015, 02:49 PM
mamort mamort is offline
Join Date: Jun 2015
Posts: 18
Use Erikvdb code above to understand event based solution then take a look at the below references

"<animationpath>.addEventAtEnd" animation path end event
"viz.ANIMATION_END_EVENT" avatar end event
Reply With Quote

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Modifying CAF Animations MissingAFew Vizard 5 06-11-2015 03:46 PM
random coding Saz Vizard 1 05-27-2010 05:44 PM
random speed and associated coding Saz Vizard 1 05-20-2010 04:03 AM
Trouble using custom animations for Live Characters IGoudt Vizard 0 09-24-2009 06:37 AM
problem with female animations vmonkey Vizard 1 10-07-2005 10:36 AM

All times are GMT -7. The time now is 01:05 AM.

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