Object Emitted from Mouth Help
Hi,
I currently have a head binded object that moves via animation out of the users mouth on a mouth open event. I would like the object to follow the same trajectory regardless if the user turns their face. I was wondering if there was a way to "detach" the object from being head binded after the mouth open event occurs.
Also, if the user closes and opens their mouth, the animation restarts. Would it be possible for a new object to be generated while the previous one continues playing its animation cycle?
Thanks,
Sava
Hi Sava,
Yep this is possible!
Animate Object Where Mouth Opened
Since we want to detach the object from head movement once it's started, what we can do is just copy the rotation and position of the head binding and apply it to a non head binded object.
To have better control of where our animation will be placed, we can create a placeholder under our Head Binding object that we can use as reference for the position and rotation.
Next we will create a new object with a script triggered on Mouth Opened that will apply the position/rotation of our placeholder to our animation. We'll start by creating an input to get references to our placeholder and animation object.
Then from the placeholder, let's grab it's position and rotation
Then we can apply it to the animation:
Finally we'll play the animation:
Having Multiple Animations
To have objects generated when mouth is opened, we can use "copyWholeHiearchy" http://lensstudio.snapchat.com/api/classes/SceneObject/.
Instead of modifying script.placeholder directly, we will apply it to a new copy of the animation object. Above where we setWorldPosition, we will create an object. Then we will set the transform from this new object.
Since we're now copying our animation object, we can disable our original animation since we only want the instances to show up, not itself.
Now we just need to turn on our animation instance. Notably, when we use copyWholeHierarchy, the object we copied is actually it's child.
Then, we need to point our animation mixer variable to the one on this newAnimation object
Finally, when this animation ends, we want our copy destroyed. So we use startWithCallback instead of start. Note that we destroy the original object (so), not the newAnimation.
Now, when you open your mouth you should have a new object be created, starting where the mouth was, but detached from it!
Our final code:
Can't wait to see what you create with this :) Don't forget to share.
Cheers,
Jon
Jon, you are a legend, thank you so much.