Forum Discussion

🚨 This forum is archived and read-only. To submit a forum post, please visit our new Developer Forum. 🚨
my3dscene's avatar
my3dscene
Protege
12 years ago

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.

4 Replies

Replies have been turned off for this discussion
  • 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
  • "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.
  • 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.