Jump to content

Using ExecuteCodeAction with OnIntersectionEntertrigger


Wemperer2
 Share

Recommended Posts

Hello first post here.

 

I just started coding with babylon 3 days ago and not being a pro with javascript I'm having trouble trying to wrap my head around the action manager.

 

Specifically what I want to do is trigger a predefined function once a mesh is detected inside another mesh. I have a block that progresses across the screen and once it intersects with another block, I want it to simply throw an alert but I have no clue how to construct the action manager for the intersection and launching the function, tho i got the moving part down.

 

 

 

 

[edit] I figured it out. For anyone else who might stumble across this thread and need it

 

var trigger = {trigger:BABYLON.ActionManager.OnIntersectionEnterTrigger, parameter: OBJECT-BEING-ENTERED};var crash = new BABYLON.ExecuteCodeAction(trigger,                function() {                                       alert('CRASH!!!!!! BURRRRRRRR EXPLODIE NOISES');                        }); OBJECT-DOING-THE-CRASHING.actionManager.registerAction(crash); 
Link to comment
Share on other sites

Now I have a new problem. I need to reference an object created by a method in a 'class'

 

var methods = {       createBlock: function(size, x, y, z, dir){          var objRef = BABYLON.Mesh.CreateBox("box", size, scene);                objRef.position = new BABYLON.Vector3(x,y,z);                objRef.rotation.y = Math.PI/dir;                objRef.material = mats.cellWall();       }}

 

When I try to stick it into this trigger for the action it isn't detected

 

var trigger = {trigger:BABYLON.ActionManager.OnIntersectionEnterTrigger, parameter: objRef};

 

I've also tried:

 

var trigger = {trigger:BABYLON.ActionManager.OnIntersectionEnterTrigger, parameter: methods.objRef};

 

Link to comment
Share on other sites

Hello, 

 

Your object is not detected because your object (objRef) does not exist when the execudeCodeAction is created : it's a null reference, and won't work.

You have to create your object before creating your trigger, or at least keep a external reference to this object.

 

For example : 

var objRef = null;var methods = {       createBlock: function(size, x, y, z, dir){          objRef = BABYLON.Mesh.CreateBox("box", size, scene);                objRef.position = new BABYLON.Vector3(x,y,z);                objRef.rotation.y = Math.PI/dir;                objRef.material = mats.cellWall();       }}

If you have your code running somewhere, I might be able to help you more.

 

Cheers, 

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