I need help with Moving an Object with Scripts

  • First off, I don't think you _need_ scripting for this, but if you're trying to do it just to learn this might help: 

    Also note, I didn't test this code but at least it'll show you one way of doing what you want

    Also also, I'm just a dude. I don't work for Snap so this might be a completely awful way of doing this lol :) 

    // object you want to rotate assuming its attached to this script
    var object = script.getSceneObject()

    // create update event
    var updateEvent = script.createEvent('UpdateEvent')

    // "bind" the event to a function, the insides of this will now run on every frame update
    updateEvent.bind(function(eventData) {

            // runs every frame update
            // this is your func, could be called anything ex: "myFunc(eventData)"       

            // we pass in "eventData" because that is how we can get "deltaTime" which is the amount of time passed since the last update, allows for smoother animation

    // create a function that you can update 
    function onFrameUpdate(eventData) {} // empty now, we don't want to do anything

    // create mouth opened event
    var mouthOpened = script.createEvent("MouthOpenedEvent"); mouthOpened.bind(function (eventData) { print("Mouth was opened");

    onFrameUpdate = function(eventData) {
    rotateJaw(eventData) // we changed the frame update function to rotate the jaw
    } });

    // note, this wont rotate it down. You'll have to play around with it. It was copy and pasted from this example: https://lensstudio.snapchat.com/api/classes/quat/
    function rotateJaw(eventData) {
    // Degrees to rotate by var degrees = 90 * eventData.getDeltaTime(); // Convert degrees to radians var radians = degrees * (Math.PI / 180); // Axis to rotate around var axis = vec3.up(); // Rotation we will apply to the object's current rotation var rotationToApply = quat.angleAxis(radians, axis); // Get the object's current world rotation var oldRotation = object.getTransform().getWorldRotation(); // Get the new rotation by rotating the old rotation by rotationToApply var newRotation = rotationToApply.multiply(oldRotation); // Set the object's world rotation to the new rotation object.getTransform().setWorldRotation(newRotation);

    // when you want to stop the rotation you will call this
        // ie: when jaw is at your desired rotation
        onFrameUpdate() = function() {} // stops update script


    Comment actions Permalink
  • Hey, i greatly appreciate your help but i still cant get it to work.

    In the beginning you said i could archive the moving jaw without scripting? If you can tell me how that works it would be great!

    Comment actions Permalink
  • Have you tried to apply a Tween?


    Add the tween package by clicking on the Add New > Help Scripts > Tween Manager

     Now, go to your jaw object and press "add component" in the inspector and add a "Script" component. 

    You're going to want to attach "Tween Transform" which is in `Tween/TweenTypes/TweenTransform`

    then, in your tween transform. Change the "Type" to "Rotate"

    then input the start X/Y/Z and the end X/Y/Z. Make sure "Play automatically" is checked and then check to see if it works.


    If that works, we're going to want to trigger it on MouthOpen

    UNCHECK "PLAY AUTOMATICALLY": Otherwise the trigger wont work, we just wanted it checked for testing

    input a "Tween Name" in the respective field on the tween component.

    (note, scene object is 'none' because its attached to the component I want to move. You can drag the skull jaw into this field)


    Now, to get the event: Go to the "Add New" > "Helper Scripts" > "Behavior"


    Now go back to the jaw object where your tween is and "Add Component" > "Script" > "Behavior"


    Change Trigger to "Face Event"

    Then set "Event Type" to "Mouth Open"


    Now, in "Response Type" you want "Run Tween"

    Assign "Target Object" to your jaw object

    Assign "Tween Name" to what ever you set the name to above


    Hope that helps!

    Comment actions Permalink
Have a comment?

Please sign in to leave a comment.

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?



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:



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!