cnjlemm Posted November 19, 2015 Share Posted November 19, 2015 I am new to babylon and am creating a space game based on gravity and mesh intersection. Basically, my game states are being managing and determined based on if a ship mesh is intersecting with a destination or obstacle mesh. Looks something like this: scene.registerBeforeRender(function() { if (ship.canvasObject.intersectsMesh(canvasObjects[0].canvasObject, true)) { ship.material.emissiveColor = new BABYLON.Color3(0, 1, 0); PubSub.publish('COLLISION EVENT', 'collided') } for(var i = 1; i < canvasObjects.length; i ++){ if (ship.canvasObject.intersectsMesh(canvasObjects.canvasObject, true)) { ship.material.emissiveColor = new BABYLON.Color3(1, 0, 0); PubSub.publish('COLLISION EVENT', 'collided with other stuffs') } } Where ship is a prototype. When the page loads, it says that the meshes are already intersecting once, then they stop intersecting, and then they intersect again. The positions of each are (-20, 1, -20) and (25, 1, 25). I feel like there's something simple-ish here that I'm missing and I've gone through all the docs but can't figure it out. Any help appreciated! Quote Link to comment Share on other sites More sharing options...
Temechon Posted November 20, 2015 Share Posted November 20, 2015 Hello, When you update the position, actually nothing is done by Babylon: mesh positions are not *really* updated. Positions are updated when the world matrix of the mesh is updated: this step is done at the very first render.That's why you have this behaviour: - collision at first frame- render- world matrix updated- no more collision To fix your issue, you have to force the first update of the world matrix, like this: myMesh.computeWorldMatrix(true); 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.