Reverse Animation with "PlayQueued"

I have this in my code (for a walk-through section of my project).

JS Code:

cameraRoot.animation["bob"].speed = -1;
cameraRoot.animation["bob"].time = cameraRoot.animation["bob"].length;
cameraRoot.animation.PlayQueued("bob"); //, QueueMode.PlayNow);

In the code the user can click on a button to move one step forward in the instructions. If for whatever reason they want to go back they can hit the “back” button and the idea is the camera animation should play in reverse. The problem is no matter what I do it always plays the clip forward, even if I set a negative playback speed.

What I was wondering is if this is an issue with the “PlayQueued()” method because all the examples I have seen use “Play()”? If that is the case, is there a better technique to make sure the clip is played through all the way before the next clip is played?

Thanks,
Grant

2 Answers

2

The correct code for what you are doing is:

var newstate = cameraRoot.animation.PlayQueued("bob"); //, QueueMode.PlayNow)
newstate.speed = -1;
newstate.time = newstate.length;

As per the docs, PlayQueued creates a new animation state.

This does work but I also ran into a glitch with it. The problem I have is I am trying to queue another clip after the reversed one and when I do that it seems to not let the first one complete before playing. It would look like this in code var newstate = cameraRoot.animation.PlayQueued("bob"); //, QueueMode.PlayNow) newstate.speed = -1; newstate.time = newstate.length; cameraRoot.animation.PlayQueued(idleClipName); The reverse playback does work if I don't try to queue the next clip. Once I try to do that it clobbers the first clip. Any thoughts? Grant

Was this meant as a comment to my answer, or as a new answer to your question?

Yes, I messed up and meant to post it as a comment to your answer. DOH!

Grant, you are correct, there is a glitch when you try to do another PlayQueued after a reversed AnimationState. The problem is when you set your temporary AnimationState (in the example “newstate”) to the exact length of the animation. PlayQueued sees that, and thinks “oh, that one is already done, play the next!”. SOO, the work around is instead of

newstate.time = newstate.length;

use something like

newstate.time = newstate.length - 0.01f;

We’re just subtracting an arbitrary amount of time so that the next PlayQueued doesn’t fire off immediately.