Showing results for 
Search instead for 
Do you mean 
Reply
Solved! Go to solution

Wait for Self Animation to finish

I try to animate a simple workstation, where an incoming MU is:

1. placed on a lift

2. the lift moves up

3. The lift rotates

4. The assembly is done(no animation)

5. The lift rotates back

6. The lift moves down

7. Mu leaves the station.

 

Steps 1 and 2 work well.

I use the selfanimation of the object "lift" in the station. It has a selfanimation "up" and "rotate" .

For step 2 I use in the entrance method of station ST104:

 

var ani:=ST104._3d.getObject("Lift").SelfAnimations;
var MUani:=ST104._3D.MUAnimations;
ani.up.schedule
ani.playAnimation

After this step 3 should be performed. I tried to do it like this:

var ani:=ST104._3d.getObject("Lift").SelfAnimations;
var MUani:=ST104._3D.MUAnimations;
ani.up.schedule
ani.playAnimation
ani.rotation.schedule
ani.playAnimation

However then the two animations are done at the same time, and the rotation is not completed until 90 degrees.  This does work do, if I only use the rotation selfanimation.

For step 5 and 6 I want to do the animations backwards using false in the schedule like this:

var ani:=ST104._3d.getObject("Lift").SelfAnimations;
var MUani:=ST104._3D.MUAnimations;
ani.up.schedule(false)
ani.playAnimation
@.move(drain)

But then the animations dont play and the Mu leaves the station right away.

How do I solve the problems and can I use "Waituntil" to wait for the animation to finish.

 

 

3 REPLIES
Solution
Solution
Accepted by topic author Jappie_166
‎01-02-2017 07:55 AM

Re: Wait for Self Animation to finish

Self animations are managed in blocks. This means that, as long as you do not start a new animation block, every newly scheduled is added to a previously existing one if there already is one.

Important to know here is that playAnimation only starts an animation in the sense that the time when playAnimation is called, is remembered to correctly play the animation in the following simulation.

For your step 3, this means that  the first call to playAnimation has no immediate effect. I think, what you try to do is to let Plant Simulation wait for finishing the first animation to start the second one.

This can be done with the following code instead:

var ani:=ST104._3d.getObject("Lift").SelfAnimations;
ani.up.schedule
ani.startNextAnimationBlock
ani.rotation.schedule
ani.playAnimation

Now, if simulation events are done between different animations, I find it best to manage if the code starts with a call to ani.resetAnimation to set the animations to a defined, unanimated, state.

 

 

About your last question: There is no waituntil to wait for animations to be finished, but you can ask how long animations will still take, so you can wait such a timespan:

var t := ani.EstimatedTotalAnimationTime
wait t

In your example, this might look like this:

 

var ani:=ST104._3d.getObject("Lift").SelfAnimations;
ani.up.schedule(false)
ani.playAnimation
wait ani.EstimatedTotalAnimationTime
@.move(drain)

Re: Wait for Self Animation to finish

[ Edited ]

It now work in the right order and at the right time. However, the schedule(false) doesn't work like it should or like i thought it would work. Now it does the exact same thing as without the false boolean. I was looking for the backwards animation of the animation

 

Re: Wait for Self Animation to finish

That is correct - if you do not pass the parameter, an animation is played in forward direction. If you pass it, it is played forward in case of false being passen and backwards in case of true being passed.