Sign in to follow this  
mwissink

How to properly remove physics joint

Recommended Posts

I have recently run into a problem with the physics joints in Babylon. I add a distance joint between two impostors in my scene, but after some time, I would like to remove that joint. Currently on the docs, there is no reference to a removeJoint function, and after looking into some of Babylon's source code, I found the function

link: https://github.com/BabylonJS/Babylon.js/blob/master/src/Physics/babylon.physicsEngine.ts

However,  the function appears as if it is not complete, and I am unsure of the proper way to access it. 

Is there a way to properly remove a physics joint?

Share this post


Link to post
Share on other sites

Finally I can help someone :P 

Keep your jointAB in a variable so you can use it later:

scene.getPhysicsEngine().removeJoint(meshA.physicsImpostor,meshB.physicsImpostor,jointAB);

If you want to see my project with helicopter able to crash when forces between body elements are to high just ask me.

Share this post


Link to post
Share on other sites

that's an interesing one :)

A spring joint is actually not a joint, it is an external constraint that calculates the forces it applies on each frame.

This is why removing a spring joint doesn't work. It is specific to this joint and this physics engine. This should, however, be working, as we do abstract the spring aas a joint. To overcome this (temporarily) you can do the following:

https://www.babylonjs-playground.com/#4J9JBX#2

I will add this as an issue.

 

Share this post


Link to post
Share on other sites

Hi @RaananW,

Thanks for the reply and example. Would you like me to add a github issue?

For the use case I am thinking, I will have many spring joints attached to a given sphere and would like to be able to select which joint I would like to remove. I suppose I could do this by just keeping track of what order constraints are added to the queue but would certainly appreciate another option.

Thanks again!

Share this post


Link to post
Share on other sites

Oh, and please create an issue for the second request (removing a specific joint, if more than one is connected to the same impostors). It requires a small architecture change, which I am not sure we will do in 3.3.

Thanks :) 

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.