Jump to content

Catch collision point with moveWithCollisions


Arte
 Share

Recommended Posts

Hey @TomaszFurca (good to see you again)... umm... you were also seeking precision "point of intersect" at one time, right?

@Arte - I think a "picking ray" can give you a precise point-of-intersect, onCollideObservable, or ActionManager OnIntersectionEnterTrigger. With intersectsMesh... not sure.

And yes, looping through a pile of mesh... checking EACH for intersection with something... sucks.

Possibly, onCollideObservable and onIntersectionEnterTrigger can avoid that looping.

First, let's "roll out" Tommy's barrels, again.

https://www.babylonjs-playground.com/#WWCK0#40

WASD keys move LEFT barrel1, and SHIFTED WASD keys move RIGHT barrel2.  Watch console.

The ONLY intersection system active by default in this scene... is a barrel2 (right one) actionManager OnIntersectionEnterTrigger in lines 134-143.  AND... it is NOT WORKING for some reason.  You can use 'd' to move barrel1 into barrel2, or use 'A' to move barrel2 into barrel1.  It never triggers.  This is POSSIBLY due-to the method we use to move the barrels.  .moveWithCollisions() might not be compatible with actionManagers.  But, it could be a Wingnut mistake, too.

Try setting barrel1 and barrel2 .checkCollisions = true; in lines 105 and 118.  Remember that we are currently using .moveWithCollisions() to move the mesh.  No dragging active, where moveWithCollisions() might not be usable.  After setting checkCollisions true on both barrels, moveWithCollisions IS stopping the mesh when it collides , but moveWithCollisions() is seemingly ignored by actionManager OnIntersectionEnterTrigger.

Still, likely a Wingnut mistake... I make those quite often.  :)

Let's move on... 

Highlight codeblock lines 134-143 and tap control-/ to disable that block of code.

Highlight codeblock lines 124-132 and tap control-/ to enable that block of code.

RUN!  :)

Now we have collide observers on both barrels.  Try some A and D keys, and some shifted A and D keys.  When a moving box collides with another, the onCollide on the moving box... DOES trigger.  Its 'd' variable IS the mesh it collided-with.  Watch console reports coming from lines 125 and 130... both printing d.name to console.

Okay, I don't know if ANY of this crap can be used to avoid looping through all intersect-able mesh in a scene, but maybe.  The BJS observer/observables system is already a "loop through everything that needs observing" -system, so, it would be wise to use THAT as your "checking loop", I think.

Smarter people may comment soon.  Geez, let's HOPE SO, anyway.  :D 

At least we have a cool testing-playground, eh?  I suppose we should try a  NON-moveWithCollisions() movement method, eh?  Learn from that, too. Hope this helps.

Link to comment
Share on other sites

Hey Wing...

This forum without you like "lake without any fish" :D;)

 

onCollideObservable =  best crap :lol: (I'm avoiding loop with this crap)

Now I need just find witch face is collided, but I can calculate from last position which direction it's moving.

Thank you for your help - AGAIN.

Link to comment
Share on other sites

Good tips. Already changed looping my colliders array in scene after render function to action manager, because action manager is fired only when object intersect, so i do need to check all colliders in camera frumstrum. Next good point to optimize my game.

Also I fixed PG https://www.babylonjs-playground.com/#WWCK0#41. You need to set parameter in action manager. Parameter value is mesh with which you want register function.

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...