Collisions with stretching meshes

Dear Babylon community,

I’m currently trying to implement some basic collision detection while dragging, but I got a bit stuck. I have walls that are anchored to a corner mesh that I would like to drag around, changing the walls afterwards.

I made a first example:

If you drag the red sphere, the green wall is moving, and it cannot be moved over the blue wall (using two hinge joints, works quite nicely).

Now, I’d like the green wall to stretch and shrink depending on the distance of the red sphere while still colliding with the immovable blue wall. The other anchor point will always be fixed. I looked into slider joints and distance joints, but I actually do not really understand how to implement the behavior I’m looking for.

I’d especially like to get to the point where I could attach multiple walls to the same corner, e. g. as in these two playgrounds:

Do you have some tips for me how I can reach the desired outcome?

Kind regards,

Hmm, I can’t say I’ve seen people use physics to do this type of collision. Maybe @RaananW or @Cedric has ideas?

1 Like

I’ve never seen this use case before. I’m wondering if trying to fit this use case with physics is a good idea?
I mean, it can take days of research,tries and failure before having something that potentialy works…no guarantee on that.
This said, if you use case fundamentals is about 2D segments and segment intersection, then I’d just do 2D calculation.

There is this thread : geometry - How do you detect where two line segments intersect? - Stack Overflow

I suggest to find the root algorithm and stick with something simple, that’s easier to debug with deterministic behavior.

Am I missing something?


No, I think both of you are right. We will stick to basic geometry to solve our issue. Thank you for your time!

1 Like