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

Head Tilt - Left / Right

  • Hi Jonathon, 

    What effect are you trying to trigger with the head tilt? Are you asking if the Lens will still track and apply to the head as it moves? If the face is still facing front, the head can tilt. However, if the face goes in profile, the Lens will not apply to the face correctly. 

    Cheers,

    Neha 

     

    Comment actions Permalink
  • What I'm trying to do is detect if this users head tilts left or right for a custom script. There will be a different function triggered depending on the direction of the head tilt.

    Comment actions Permalink
  • HI, Jonathon!

    Here is a super simple script you could start with:

    //@input Component.Head head 
    //@input float threshold = 0.2 {"widget" : "slider", "min" : 0, "max" : 1, "step" : 0.01}

    var headTransform = script.head.getSceneObject().getTransform();
    const eps = 0.1;
    var State = { "NONE": 0, "LEFT": 1, "RIGHT": 2 };
    var currentState = State.None;
    var x;


    script.createEvent("UpdateEvent").bind(onUpdate);

    function onUpdate() {
        if (script.head.getFacesCount() > 0) {
            x = headTransform.up.x;
            if (Math.abs(x) < eps) {
                if (currentState != State.NONE) {
                    currentState = State.NONE;
                    onCenter();
                }
            } else if (x < -script.threshold) {
                if (currentState != State.LEFT) {
                    currentState = State.LEFT;
                    onLeft();
                }
            } else if (x > script.threshold) {
                if (currentState != State.RIGHT) {
                    currentState = State.RIGHT;
                    onRight();
                }
            }
        } else {
            if (currentState != State.NONE) {
                currentState = State.NONE;
                onLost();
            }
        }
    }

    function onLeft() {
        print("LEFT!");
    }

    function onRight() {
        print("RIGHT!");
    }

    function onLost() {
        print("Head Lost")
    }

    function onCenter() {
        print("Back to center");
    }

    Please create head Binding and set it as an input of this script.

    Best

    Olha

    Comment actions Permalink
  • Hello, 

     

    Thank you for taking the time to help out! ...  I tested this script but it doesn't quite work. 

     

    It only triggers when I look to my right... however it triggers right and then triggers left when the head is returning to normal position.

     

    The effect I'm looking for is imagine 2 cards at the top left and top right of the screen...  user needs to nod upward and to the left or upward and to the right to indicate which card they have chosen.

    So it's important that the direction is only triggered once to indicate what choice was made.

    Comment actions Permalink
  • Hi! I've updated script above to use threshold. Please tweak the value as needed. 

    Let me know if that works!

    Best

    Olha

    Comment actions Permalink
  • Hi :) There seems to be a problem with this script that once you have tilted either right or left that you cannot tilt the same way again for it to call the on direction function. E.g. if you have tilted left once, you cannot tilt left again until you have tilted and triggered a call to onRight()

    Comment actions Permalink
  • Hi, Balraj Bains! You are right! I've added a couple lines to the script above to support that, let me know if that works!

    Also if you come up with more robust solution - feel free to share it with the community! 

    Thanks!

    Olha

    Comment actions Permalink
  • Thank you Olha! I think I had the same solution :)

    Comment actions Permalink
  • Olha Thank you for the code which works perfectly. Can I trouble you to explain how using the head Transform's up directional vector can get you the rotation of the head on the z-axis?

    x = headTransform.up.x
    Comment actions Permalink
  • Hi, Boon.Metaverse!  Thank you! 

    The UP vector is a normalized vector of a head transform that is pointing up 

    In this case threshold setting represents an absolute value of |sinA| that corresponds to angle of approximately 11 degrees

    You can easily modify script to make inputs more understandable :

    //@input float angle {"widget" : "slider", "min" : 0, "max" : 90, "step" : 0.1}
    script.threshold = Math.abs(Math.sin(script.angle / 180 * Math.PI))

    BTW this asset is available on the Asset Library now!

    Best

    Olha

     

    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!