Metalx1000 Posted June 11, 2014 Share Posted June 11, 2014 I'm currently working on a game,Playable here:http://filmsbykris.com/scripts/metal_bulletsCode Here:https://github.com/metalx1000/metal_bullets/Right now I'm using intersectsMesh to check for collisions.I have two questions.1) Is there a better way to do this?2) Can you check if an object intersects another without having to check them all?Here is my current code for enemy collisions. for(var i=0;i<Obstacles.length;i++){ var obs = Obstacles[i]; //console.log(wall.name + " is " + this.mesh.intersectsMesh(wall)); var col = this.check_collision(obs); if(col){break;} }Every time an enemy is updated/moves, I check it against ever object in the "Obstacles" array (which is an array with all meshes that are obstacles for enemies).I use the Obstacles array, that I created, so that I don't have to check every mesh in the scene, but it still seems like there should be a better way, because this is a lot of checking over and over again.I'm hoping there is a way to have it check if it's intersecting anything and then just check what that object is and if it's in the Obstacles array. Early on I tried using Cannon.js for this, but I had issues. Things like, if I apply physics to a wall, and that wall touched another wall, they would fly apart and hit other walls, and basically destroy the level. Also having a bunch of meshes with physics really slowed down the performance. But, maybe I'm just using it wrong.Thanks in advance for any help. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted June 11, 2014 Share Posted June 11, 2014 You can use octrees for that:https://github.com/BabylonJS/Babylon.js/wiki/Optimizing-performances-with-octrees (Scene octree in this case) You can also speedup your tests by first checking against bounding box before checking against the mesh itself Quote Link to comment Share on other sites More sharing options...
Metalx1000 Posted June 11, 2014 Author Share Posted June 11, 2014 You can use octrees for that:https://github.com/BabylonJS/Babylon.js/wiki/Optimizing-performances-with-octrees (Scene octree in this case) You can also speedup your tests by first checking against bounding box before checking against the mesh itselfThanks again DeltaKosh 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.