Jump to content

How to call a single action manager with multiple triggers.


rakesh
 Share

Recommended Posts

Hello,

In my game, i have a house with many doors, so the code for opening the door is

var doors=function(mesh)
    {
        mesh.actionManager=new BABYLON.ActionManager(Scene);

mesh.actionManager.registerAction(new BABYLON.InterpolateValueAction(BABYLON.ActionManager.OnPickTrigger, mesh, "rotation.y",Math.PI/2, 1000)).then
   (new BABYLON.InterpolateValueAction(BABYLON.ActionManager.OnPickTrigger, mesh, "rotation.y",-Math.PI/180, 1000));

    }
       doors(door01);
      doors(door02);

the above code works fine when i click on the door But,

I also have an zombie like Artificial Intelligence which also can open the doors,

so my question is, how can i call the function 'doors' when the distance between any door and AI is less than 100.

As the code is for OnPickTrigger, it is not working for AI.


  

Link to comment
Share on other sites

Hiya @rakesh, and welcome to the forum.  Take a look at http://doc.babylonjs.com/classes/2.5/action

There is an .execute method... on Actions.  So, you should be able to manually perform the action (but not the trigger).

 var doors=function(mesh)
    {
        mesh.actionManager=new BABYLON.ActionManager(Scene);

        var myAction = new BABYLON.InterpolateValueAction(BABYLON.ActionManager.OnPickTrigger, mesh, "rotation.y",Math.PI/2, 1000)).then
   (new BABYLON.InterpolateValueAction(BABYLON.ActionManager.OnPickTrigger, mesh, "rotation.y",-Math.PI/180, 1000);

        mesh.actionManager.registerAction(myAction);

    }

    doors(door01);
    doors(door02);

    scene.beforeRender=()=>{
         if (zombieNearDoor)
             myAction.execute();
    }

Something like that.  :)  It's not quite right, though.

Some might put an invisible plane on the floor, and when zombie intersects invisible plane, zombieNearDoor = true;  :)  Hope this helps.  Here's a playground that also uses .execute() in line 92... http://www.babylonjs-playground.com/#4HUQQ#99

Link to comment
Share on other sites

Hi Rakesh and welcome to the forum from me. Only on mobile at the moment so cannot try my suggestion out.

For me since your doors function is creating a new action manager each time it is called and really should be only called once per door I would not call it when the zombie was close to the door, you need a new function. Instead I would create an animation that opened and one that closed a door. The opening would happen when the zombie got close enough to the door and closing when the zombie went through the door and/or moved away from the door.

For information on creating and calling animations read http://babylonjsguide.github.io/basics/Starter

and https://doc.babylonjs.com/tutorials/animations

I see wingnut just beat me to it with an alternative suggestion. Just like buses non arrive for ages then two come at once. 

Link to comment
Share on other sites

Yep, well said, JohnK. 

Interpolators is interpolators, though.  Animations and ActionManagers both use them, I guess.  :)  http://www.babylonjs-playground.com/#BUWYF#49

A click-the-door opener/closer.  (yawn). 

Then there's @gryff's Desk Maneuver.  :)  http://www.3dworlds.ca/desk2/index.html

Clicky-clicky fun!

@thiendv used a playAnimationTrigger of an actionManager... to play animations that were built-into the mesh at modeling-time (pre-import)... here:

http://www.3dworlds.ca/thiendv/index.html

See source.  Good stuff.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...