Metalx1000

Can you intersectsMesh without checking all meshes

Recommended Posts

I'm currently working on a game,
Playable here:
http://filmsbykris.com/scripts/metal_bullets
Code 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.

Share this post


Link to post
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.