Lens for cat/dog -> trigger/behavior problem

Hello everybody,

I’m a new user of Lens Studio and I’m trying do create a Lens for animals.

I would like to play a sound as soon as the animal face is found.

But the only thing I managed to do is to set an “on tap” trigger to start playing my sound.

I also tried the “on awake” and the “on start” triggers but the sound is played before the cute animal face is found :frowning: .

So it seems like the “on tap” trigger is the only way to play my sound after the face is found.

Hope I’m wrong.

Can you help me please ?

Many thanks.

Hi!

U need to do a couple things

First, find Object Tracking Hint Controller script inside Resource panel
And double click on it
then replace all script with this one

// -----JS CODE-----
// ObjectTrackingHintController.js
// Version: 0.0.2
// Event: Lens Initialized
// Description: Controls a object tracking logo and text that appears when camera is not seeing cat, dog, hand, body.

// @input Asset.Texture hintLogo
// @input int hint = 0 {"widget": "combobox", "values":[{"label": "Cat", "value": 0}, {"label": "Dog", "value": 1}, {"label": "Cat or Dog", "value": 2}, {"label": "Body", "value": 3},{"label": "Hand", "value": 4}, {"label": "Custom", "value": 5}]}
// @input string customText {"showIf": "hint", "showIfValue": 5}
// @input Component.AudioComponent audio
// @input bool advanced = false
// @input Component.Text hintText {"showIf":"advanced"}
// @input SceneObject hintRenderZone {"showIf":"advanced"}
// @input SceneObject hintLogoImage {"showIf":"advanced"}
// @input SceneObject magnifyingGlassPivot {"showIf":"advanced"}
// @input SceneObject magnifying {"showIf":"advanced"}

var hints = ["LOOK FOR CAT", "LOOK FOR DOG", "LOOK FOR CAT OR DOG", "LOOK FOR BODY", "LOOK FOR HAND", script.customText];
var hidden = false;
var rotationSpeed = 0.025;
var t = script.magnifyingGlassPivot.getTransform();
var additionalRotation = quat.angleAxis(rotationSpeed, vec3.forward());

function initialize() {
    global.tweenManager.startTween(script.magnifying, "transitionin");
    global.tweenManager.startTween(script.hintLogoImage, "transitionin");
    script.api.show = show;
    script.api.hide = hide;
    script.api.updateHintText = updateHintText;

    if (script.hintLogo) {
        script.hintLogoImage.getComponent("Component.Image").mainPass.baseTex = script.hintLogo;
    }

    updateHintText(script.hint);
}

function onUpdate() {
    if (global.scene.isRecording()) {
        hide();
        return;
    }

    rotateMagnifyingGlass();
}

function show() {
    if (!hidden) {
        return;
    }

    hidden = false;

    script.hintRenderZone.enabled = true;

    global.tweenManager.startTween(script.magnifying, "transitionin");
    global.tweenManager.startTween(script.hintLogoImage, "transitionin");
}

function hide() {
    if (hidden) {
        script.audio.play(1)
        return;
    }

    hidden = true;

    global.tweenManager.stopTween(script.magnifying, "transitionin");
    global.tweenManager.stopTween(script.hintLogoImage, "transitionin");
    global.tweenManager.resetObject(script.magnifying, "transitionin");
    global.tweenManager.resetObject(script.hintLogoImage, "transitionin");

    script.hintRenderZone.enabled = false;
}

function rotateMagnifyingGlass() {
    var currentRot = t.getLocalRotation();
    t.setLocalRotation(currentRot.multiply(additionalRotation));
}

function updateHintText(hintNumber) {
    if (!script.hintText) {
        print("ObjectTrackingHintController, ERROR: Please make sure Hint Text object is set under the advanced checkbox");
        return;
    }

    script.hintText.text = hints[hintNumber];
}

var updateEvent = script.createEvent("UpdateEvent");
updateEvent.bind(onUpdate);

initialize();

Then add your audio component

2 Likes