Jump to content

OnIntersectionEnterTrigger not triggering with camera


jameskmonger
 Share

Recommended Posts

I'm using Babylon.js `2.4.0`.

I have a mesh (in the shape of a couch) loaded from a `.obj` file, and a camera set up like this:

    let camera = new BABYLON.FreeCamera('camera1', new BABYLON.Vector3(0, 2, 0), scene);

    camera.checkCollisions = true;
    camera.applyGravity = true;
    camera.ellipsoid = new BABYLON.Vector3(1, 1, 1);
    camera.attachControl(canvas, false);
    camera.speed = 0.5;
    camera.actionManager = new BABYLON.ActionManager(scene);

I want to set up an event so that when I walk through the couch, "intersection" is logged to the console:

    let action = new BABYLON.ExecuteCodeAction(
      { trigger: BABYLON.ActionManager.OnIntersectionEnterTrigger, parameter: { mesh: couchMesh }},
      (evt) => {
        console.log("intersection");
      }
    );
    
    this.camera.actionManager.registerAction(action);

When I walk through the mesh, nothing is logged to the console. 

I've created an example on the [Babylon.js Playground](http://www.babylonjs-playground.com/#KNXZF#1) using an example that they provide to check that it wasn't a problem with my mesh or camera set up, and it doesn't appear to be (the playground doesn't work either).

Link to comment
Share on other sites

Hiya @jameskmonger, welcome to the forum!  Sorry it has taken so long to receive a reply.

I don't think cameras can use onIntersectionEnterTrigger... because cameras are not a mesh.  I'm not REAL sure about that, but that COULD be the problem.

http://www.babylonjs-playground.com/#KNXZF#2

Here, I built a "camera gizmo" mesh, made it invisible, parented it to the camera, and then put the intersect actionManager on the camgizmo.  Seems to be working.

Perhaps others will have comments or better ideas.  Again, welcome, good to have you with us.

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...