tr00n Posted May 27, 2015 Share Posted May 27, 2015 Hi guys,I've been working on getting a basic prototype up and running for Dialo'esque game. All is well and I'm now at the part where my 'character' has to interact with objects laying around in the world. The way that I've done is that I create multiple random cubes and position them randomly. When my character touches each of these objects I'd like for it to execute some custom code for that particular object. The code that I'd like to execute could be something like increment food points but also at the same time inactivating that object. Thus I collide with it again it should trigger no response. Now, I've had success experimenting with the action manager and all works well with a single object. However when I create many of the same object it only seems to work once. It seems that all these objects share the same parameter (is_used) and that it doesn't get instantiated properly. In Three.js I was able to set this up per instance of the object and then I was able to turn off the is_used boolean for a particular instance of that object. I will continue digging for a solution but any input is welcome This is the code that defines a single of these randomly dispersed objects: function foodRation(size){ var box = BABYLON.Mesh.CreateBox("box", size, scene); box.material = new BABYLON.StandardMaterial("Mat", scene); box.material.diffuseTexture = new BABYLON.Texture("/assets/ground.jpg", scene); box.material.diffuseTexture.hasAlpha = true; box.position.x = getRandomInt(3, 20); box.position.y = getRandomInt(3, 20); box.is_used = false; box.collisionsEnabled = true; box.checkCollisions = true; box.actionManager = new BABYLON.ActionManager(scene); var collisionTrigger = { trigger: BABYLON.ActionManager.OnIntersectionEnterTrigger, parameter: meshPlayer }; var collisionFunc = function(){ if(box.is_used==false) console.log("code that adds food to character"); box.is_used = true; }; box.actionManager.registerAction(new BABYLON.ExecuteCodeAction(collisionTrigger,collisionFunc)); } Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted May 27, 2015 Share Posted May 27, 2015 humm...this should work..I cannot see a reason why it won't execute it for every box. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted May 27, 2015 Share Posted May 27, 2015 Do you mind creating a Playground repro so I will be able to debug it? Quote Link to comment Share on other sites More sharing options...
tr00n Posted May 28, 2015 Author Share Posted May 28, 2015 Hi Deltakosh,Thanks for your reply. Whilst I was recreating it in the playground repro I actually found out what my problem was. It was a simple typo where I had accidentally declared the Y position rather than the Z position of the boxes:box.position.x = getRandomInt(3, 20);box.position.y = getRandomInt(3, 20);My camera is orthographic so I didn't notice that the boxes were in fact on top of each of other. Now that I've changed it to Z rather than Y it all works beautifully. Sometimes its those simple things but I can't but feel a little silly Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted May 28, 2015 Share Posted May 28, 2015 No problem this kind of things happen and this is why I love TypeScript 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.