The forum on this site is closed for new comments and posts. Continue the conversation in the new forum, and learn more here.

Trying to do Marco Polo with approach but baby keeps crying...

  • This post can be deleted I just re-invented the wheel here...not even a nice looking wheel!!

    with this you can use seperate animation and audio (def needs some TLC!)

     

    // @ui {"widget": "group_start", "label": "Peek-a-boo Settings"}

     

    // @input SceneObject object1

     

    // @input SceneObject cameraObject

    // @input float triggerRadius

     

    // @ui {"widget": "group_end"}

     

    //var setups for approach for peek a boo..

    var minManipDist = script.getSceneObject().getFirstComponent("Component.ManipulateComponent").minDistance;

    var maxManipDist = script.getSceneObject().getFirstComponent("Component.ManipulateComponent").maxDistance;

    script.triggerRadius = clampNumber(script.triggerRadius, minManipDist, maxManipDist);

     

     

    //the function to hide object

    function peeka(){

    script.object1.enabled = false;

    }

     

    //the function to show object

    function Boo(){

     

    // @ui {"widget": "group_start", "label": "Boo reveal Settings"}

    // @input SceneObject objectboo

    // @input Component.AnimationMixer animationMixer1

    // @input string animationLayerName1 = "BaseLayer"

    // @input float animationWeight1 = 1.0 {"widget":"slider", "min": 0, "max": 1, "step": 0.01}

    // @input float animationStartOffset1 = 0.0

    // @input int numberOfLoops1 = 1

    // @ui {"widget": "group_end"}

    // @input Component.AudioComponent audioRex

    script.audioRex.play( 1 );

    script.objectboo.enabled = true;

    if(!script.animationMixer1)

    {

    script.animationMixer1 = script.getSceneObject().getFirstComponent("Component.AnimationMixer");

    }

    if(script.animationMixer1)

    {

    script.animationMixer1.setWeight(script.animationLayerName1, script.animationWeight1);

    script.animationMixer1.start(script.animationLayerName1, script.animationStartOffset1, script.numberOfLoops1);

    }

    }

     

    // inital function reset on lens start

    function onLensTurnOnEvent()

    {

    peeka();

    }

     

    var turnOnEvent = script.createEvent("TurnOnEvent");

    turnOnEvent.bind(onLensTurnOnEvent);

    // end of start and reset

     

    // the Function that runs on every frame for checking the distance

    // Function runs at the start of every frame if not in radius of collission make sure object is hidden with peeka function

    function onUpdateEvent(eventData)

    {

     

    if(script.cameraObject)

    {

    // Distance between the camera and the object is used to determine when to trigger the approachs hiddne status

    var dist = script.cameraObject.getTransform().getWorldPosition().distance(script.getSceneObject().getTransform().getWorldPosition());

     

    // If the object isn't hidden unhide it

    if(dist <= script.triggerRadius)

    {

    Boo();

    print("Peeka-hide");

     

    }

    }

    }

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

    updateEvent.bind(onUpdateEvent);

    // end of function frame start

     

     

    // Clamping number utility function //picked up from approach un-sure of use.

    function clampNumber(val, min, max)

    {

    return Math.min(Math.max(val, min), max);

    }

     

     
    Comment actions Permalink
  • Awesome, glad you found a solve!

    FWIW, I did write a simplified approach script a while back that can work outside the template. Might be worth looking at. It's very similar to what you are doing. 


    // @input Component.SpriteVisual spriteBefore
    // @input Component.SpriteVisual spriteAfter
    // @input SceneObject cameraObject
    // @input float triggerRadius

    // Function runs at start of lens
    function onLensTurnOnEvent()
    {
    approached = false;
    script.spriteBefore.enabled = true;
    script.spriteAfter.enabled = false;
    }
    var turnOnEvent = script.createEvent("TurnOnEvent");
    turnOnEvent.bind(onLensTurnOnEvent);

    function onUpdateEvent()
    {
    if(script.cameraObject)
    {
    var dist = script.cameraObject.getTransform().getWorldPosition().distance(script.getSceneObject().getTransform().getWorldPosition());

    if(!approached && dist <= script.triggerRadius)
    {
    onApproach();
    }
    }
    }
    var updateEvent = script.createEvent("UpdateEvent");
    updateEvent.bind(onUpdateEvent);

    function onApproach()
    {
    if( !approached )
    {
    print( "APPROACHED" );
    approached = true;
    script.spriteBefore.enabled = false;
    script.spriteAfter.enabled = true;
    }
    }
    Comment actions Permalink
  • Oh also a little tip, the editor on the forum if you click the little Paragraph icon has a "Code" formatting style. This might make you code show up a little cleaner in your forum posts. Sometimes I still have to fix some tab / spaces problems. But it generally does a good job. 

    Comment actions Permalink
  • Hey Travis, once again thank you for advice and writting cleaner code

    have also edited my post to "code"

    Comment actions Permalink
  • I recently created the baby lens and its looking very nice I tried it and you can visithere to experience it.

    Comment actions Permalink

We're here to help! We just need a little bit of information...

What system are you using?

Have you downloaded the latest version of Lens Studio?

Please download the latest version of Lens Studio. If you still run into this issue, please come back and report it!

Is this issue causing Lens Studio to crash?

What system do you run Lens Studio on?

Version

Graphics

Follow the next steps to help us solve your issue:

  • Copy and paste this text into your TerminalCommand Window
    open ~/Library/Preferences/Snap/Lens\ Studio/ %LOCALAPPDATA%\Snap\Lens Studio Copy Text
  • Press ReturnEnter to run the command. The Lens Studio folder will automatically open
  • Prepare to upload your files: zip the "Log" Folder by right-clicking and choosing "compress."
    Locate the Log.txt file right above it.

    Attach a screenshot of the issue:

Name:

Email:

What is this most relevant to?

Please enter a brief description of your issue:

Thanks for submitting this issue.

Unfortunately, it's likely due to the operating system or hardware you're using – since they don't meet the system requirements for Lens Studio.

Still, we hear you loud and clear, and are logging the issue in case there's ever a workaround we can provide!

Minimum Requirements

Operating System: Windows 10 (64 bit); MacOS 10.11+

Hardware: Minimum of Intel Core i3 2.5Ghz or AMD Phenom II 2.6Ghz with 4 GB RAM; Intel HD Graphics 4000 / Nvidia GeForce 710 / AMD Radeon HD 6450 or better; screen resolution of 1280x768 or higher

We'll try to resolve this issue as soon as possible. Thanks for letting us know about it!

Keep an eye out for a followup email from us. We may have a couple more questions for you, or we might already have a solution to offer.

Happy creating!