Jump to content

Collision takes place even when not colliding.


JohnK
 Share

Recommended Posts

It all started when two meshes in the project I am doing would only show an intersection when they were overlapping by several units. Rather than try to explain the steps needed to reproduce what was happening in the project I thought I would see what happened in the playground. Now I must have done something stupid because

box1.intersectsMesh(box0, false)

always read true whatever the positions of box0 and box1.

 

My trial is at http://www.babylonjs-playground.com/#MABFZ

 

I have tried it with and without setting checkCollisions for the meshes and the scene.

 

Waiting to kick myself when someone points out what I have done wrong.

Link to comment
Share on other sites

Thank you DK. Need to keep remembering that code can be done before rendering and that calling computeWorldMatrix solves a lot of problems.

 

Partially solves the project problem provided I do not scale the meshes, which I want to do. Will keep working on the code to see if I can work out where to adjust.

Link to comment
Share on other sites

  • 5 months later...

Hey,

 

I've just played a bit with intersectsMesh and I see something strange happening.

 

http://www.babylonjs-playground.com/#11JY4O#1

 

Here we can move the objects with the mouse. The green cube is the "collider one".

 

For the mesh currently moved (red sphere for instance), I record the current position if no intersection occur. When intersectMesh with the green box returns true, I don't record the current position, and instead I reposition the object to the latest safe position recorded (where no intersection previously occured). Since this position has been calculated as "safe" by intersectMesh, no intersection should be detected there. But while it works well the first two or three times, then intersection strangely occurs also in safe recorded positions.

You can check the console to see locations logged.

 

Am I doing something wrong, or intersectMesh doesn't give always same answer for two identical situations (maybe it is processed at the quantum level :lol: ) ?

Link to comment
Share on other sites

The technique that DK gave to me in this thread seems to alleviate the problem.

 

Line added before checking intersection

currentMesh.computeWorldMatrix(true)

However the jump from intersection to safe can be sometimes not smooth. Something to do with when the timing when rendering and intersect checking takes place????

 

http://www.babylonjs-playground.com/#11JY4O#6

Link to comment
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...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...