Sign in to follow this  
joshcamas

[Solved] Strange problems with intersectsMesh()

Recommended Posts

Hia guys!

I'm sure ya'll are familiar with the awesome intersection demo here on the PG:
http://playground.babylonjs.com/#YMFIP

Well, in my own game I'm having massive problems. Mainly, the mesh never collides with another mesh.
I've tried showing bounding boxes to make sure their good, as well as switching between OBB and AABB, and nothing works.
However, if I try checking intersection by itself (mesh.intersectsMesh(mesh)), then it works.
I assumed it may have had to do with scaling or something, so I went and tried to replicate it on the PG.

After trying to replicate it, I found an even stranger problem!
It seems if you create an object after scene initiation, intersections won't work, or something?
http://playground.babylonjs.com/#15VR2V#1

But this time, it always intersects with plane, no matter where I place the plane or the sphere! WHAT!?
And I've made it so it waits a tick before it creates it, and have also tried waiting 10 ticks and such, just in case. 

Any ideas? Am I doing something wrong?
Thanks!

Share this post


Link to post
Share on other sites

In your second playground, both the if and else are red, but that wasn't the problem. I changed your playground so that it checks for collisions a frame after the objects have been added to the scene:

http://playground.babylonjs.com/#15VR2V#3

And it works just fine. It adds the meshes after 120 frames, and it checks for collisions at frame 121. Black is no collision, red is collision.

Maybe that helps
 

Share this post


Link to post
Share on other sites

Actually, is there a way to not do this? Is there some sort of generation that can be forced out of tick? Cause that'd be rad :D
EDIT: Just kidding! Simply run plane.computeWorldMatrix(true) and sphere.computeWorldMatrix(true) and boom! :D <3 

Share this post


Link to post
Share on other sites

Does intersectsMesh() works with lines ? And with complex loaded models or it makes a bounding box ?

Does intersectsMesh() works with a box scaled, rotated etc ? (or i have to compute matrix)

Does IntersectsPoint() works fine with a mesh moving fast, good performance ?

 

I faced some issues.

 

(Is it a good practice to detect collisions with raycast ?)

 

 

Share this post


Link to post
Share on other sites

intersectsMesh rely on bounding boxes and bounding spheres, so if your mesh has a BBOX (not sure for lines), it works whatever its origin (loaded or built-in).

By default, the intersections are computed on axis aligned bounding boxes (AABB) even for scaled meshes, unless you specify you want the precise mode what enables OBB (oriented bounding boxes) computations, then taking in account rotations. In brief, you don't need to compute matrices.

If you need a better accuracy than bounding boxes only, you have to use a physics engine what provides impostor more specific shapes.

No idea about intersectsPoint(), didn't test it up now ...

Generally, raycast computations are far more CPU intensive than BBOX computations.

Share this post


Link to post
Share on other sites

Thx for your answer.

Finally the little issue I had with lines collision is simply because the engine takes the position centered of the line and not the points :

var lineShoot = BABYLON.Mesh.CreateLines("lines", [
    new BABYLON.Vector3(2, 8.8, -2),
    new BABYLON.Vector3(2, 8.8, -4)
], scene, false);

 

For example, here x:2 won't be recognized. It's better to put the points at x:0 and lineShoot.position.x = 2.

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...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.