Quantcast
Channel: Babylon.js
Viewing all articles
Browse latest Browse all 388

Issue with intersecting meshes on initialization

$
0
0

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[i].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!

Viewing all articles
Browse latest Browse all 388

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>