Skip to main content
Up and Coming
September 8, 2014

Select by looking something for a few seconds

Hi guys,
at the moment I am working in Javascript to add this feature in my project. However I am having some issues.

What I am doing is attach a non renderable stretched box to my right camera (like a ray from my head) in order to collide with a second box when you look at it, and then "yield" for a few seconds.

Just wondering to know if any of you guys have a better script than my non functional Javascript one.
    This topic has been closed for replies.

    4 replies

    Inspiring
    September 9, 2014
    you could do something like:

    var LookingAtObject : bool = false;
    var LookAtTimer : float = 0.0f;
    var LookAtTimeLimit : float = 3.0f

    function Update()
    {
    if (LookingAtObject == true){
    LookAtTimer += time.deltaTime
    }

    if (LookAtTimer >= LookAtTimeLimit){
    doSomething
    }


    }


    function OnTriggerEnter (other : Collider) {
    LookingAtObject = true;
    }

    function OnTriggerExit (other : Collider) {
    LookingAtObject = false;
    LookAtTimer = 0.0f;
    }


    I havent tested this but that should be the just of it
    my3dsceneAuthor
    Up and Coming
    September 9, 2014
    "MikeF" wrote:
    you could do something like:

    var LookingAtObject : bool = false;
    var LookAtTimer : float = 0.0f;
    var LookAtTimeLimit : float = 3.0f

    function Update()
    {
    if (LookingAtObject == true){
    LookAtTimer += time.deltaTime
    }

    if (LookAtTimer >= LookAtTimeLimit){
    doSomething
    }


    }


    function OnTriggerEnter (other : Collider) {
    LookingAtObject = true;
    }

    function OnTriggerExit (other : Collider) {
    LookingAtObject = false;
    LookAtTimer = 0.0f;
    }


    I havent tested this but that should be the just of it

    Tnks master mike, I will let you know how it works.
    my3dsceneAuthor
    Up and Coming
    September 10, 2014
    it works, I had to tweak a bit the code, since "Bool" wasn't very friendly with Javascript, but the structure is the same. I have also added animations and sound and works perfectly.
    Tnks Master.
    Inspiring
    September 10, 2014
    no problem, glad i could help!