Mouth Opened Trigger works only after the second time I open my mouth
Hello,
I am trying to create an effect where fireworks go off when someone opens their mouth. It works, but only if I open and close my mouth twice. The fireworks only go off after the first time I open and close my mouth. Any help would be greatly appreciated.Thank you. The script I am using is below.
var triggerStartTime = getTime() - script.TriggerDisableTime;
// What happens when event is triggered
function onTriggered()
{
print("FaceTriggerAnim: " + script.AnimationTrigger + " triggered");
// Called when animation ends
function animationCallback()
{
script.AnimationMixer.setWeight(script.LayerName, 0.0);
}
// Play animation layer with sound (if available)
if (script.AnimationMixer && script.LayerName)
{
script.AnimationMixer.startWithCallback(script.LayerName, 0.0, script.animationPlayCount, animationCallback);
script.AnimationMixer.setWeight(script.LayerName, 1.0);
}
for (var i = 0; i < script.play2dSprites.length; i++)
{
if (script.play2dSprites[i]
&& script.play2dSprites[i].mainPass.baseTex
&& script.play2dSprites[i].mainPass.baseTex.control
&& script.play2dSprites[i].mainPass.baseTex.control.play)
{
script.play2dSprites[i].getSceneObject().enabled = true;
script.play2dSprites[i].mainPass.baseTex.control.play(script.texturePlayCount, script.texturePlayOffset);
}
}
for (var i = 0; i < script.playAudios.length; i++)
{
if (script.playAudios[i])
{
var audioComponent = getAudioComponentForTrack(script.playAudios[i]);
audioComponent.play(script.audioPlayCount);
}
}
}
// Trigger an action if not in cooldown period
function triggerCallback()
{
if (getTime() >= triggerStartTime + script.TriggerDisableTime) {
triggerStartTime = getTime();
onTriggered();
}
}
// Setup the audio component if audio track defined
function getAudioComponentForTrack ( audioTrackAsset )
{
var trackName = audioTrackAsset.name;
if (!global.ftAudioComponents)
{
global.ftAudioComponents = {};
}
if (!global.ftAudioComponents[trackName])
{
var audioComponent = script.getSceneObject().createComponent("Component.AudioComponent");
audioComponent.audioTrack = audioTrackAsset;
global.ftAudioComponents[trackName] = audioComponent;
}
return global.ftAudioComponents[trackName];
}
// Allow fullscreen tapping if trigger is touch based
if (script.AnimationTrigger == "TouchStartEvent"
|| script.AnimationTrigger == "TouchStartEvent"
|| script.AnimationTrigger == "TapEvent")
{
global.touchSystem.touchBlocking = true;
global.touchSystem.enableTouchBlockingException("TouchTypeDoubleTap", true);
global.touchSystem.enableTouchBlockingException("TouchTypeSwipe", true);
}
var event = script.createEvent(script.AnimationTrigger);
event.faceIndex = script.faceIndex;
event.bind(triggerCallback);
Hi Ryan,
Can you give more information about how you are using this script? Is your firework effect a 2D sprite, or a 3d mesh animation?
Also, does the "FaceTriggerAnim: ... triggered" message get printed out to the Logger panel every time you open your mouth, or only the second time?
Finally, if you just want to play an animation on mouth open, it might be easier to use Behavior Script
It's a 2D sprite.
The behavior script worked, thank you.