Wemperer2 Posted November 3, 2014 Share Posted November 3, 2014 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); Quote Link to comment Share on other sites More sharing options...
Wemperer2 Posted November 4, 2014 Author Share Posted November 4, 2014 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}; Quote Link to comment Share on other sites More sharing options...
Temechon Posted November 4, 2014 Share Posted November 4, 2014 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, Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.