Jump to content

Helicopter wiggling Babylon Cannon


wo997
 Share

Recommended Posts

22 hours ago, Raggar said:

I know Cannon has a removeConstraints function, so if that's the plugin you use, maybe you could either try that, or try the executeNativeFunction function.

I found this https://doc.babylonjs.com/classes/2.4/CannonJSPlugin but it's not shown how to use it. Can you find babylon playground or any code with this (generate joint, remove joint...)?

Link to comment
Share on other sites

http://schteppe.github.io/cannon.js/docs/classes/Constraint.html#method_disable

disable... that's a way to do it using native call.  (hingeConstraint link)  (enable/disable methods are there, too, as you can see.)

console.log(scene.getPhysicsEngine()._physicsPlugin);  (the plugin).  But, yeah, I don't see any constraint disable code on the plugin.  Not deemed important enough for plugin layer.  So, go native.  :)  @RaananW and the boys made native calls easy to do.

Link to comment
Share on other sites

On 1/23/2017 at 8:38 AM, Raggar said:

http://playground.babylonjs.com/#15U9CT#42
 

On line 521/522, I tried using both world.removeConstraint and constraint.disable() without any apparent difference.

Try picking the boxes to see it in action.

Try running either of those functions natively using the function in the plugin.

I tried it and it works even on my phone smoothly. I think that the script won't create many boxes as it says because you have the same name for each of this. Am i right? I still can't see the point of native functions because I have never done this before. I remember how to paste c++ into javascript but here I get stuck.

Link to comment
Share on other sites

The name shouldn't really matter as far as I know. They still have ID's to uniquely identify every single mesh.

Try zooming out, then it doesn't run as smoothly, but that is something entirely different than this thread.

Imagine making a skyscraper you could bring down, that would be cool, but I'm not really sure Javascript is capable of doing that, in a performant way.

Link to comment
Share on other sites

ballM.physicsImpostor.executeNativeFunction(function (world, body) {
         world.removeConstraint(joint3);
});

Doesn't work, ballM is a jointed body, joint3 is a joint, should I execute this function for the body or constraint? I have no errors.

Link to comment
Share on other sites

For the constraint.

I haven't personally toyed with the function, but have you verified that the function itself works by doing something like this:

ballM.physicsImpostor.executeNativeFunction(function (world, body) {
         body.velocity.-y = 10;
});

Or maybe just log the output of the world and body, to make sure everything is right?

 

Link to comment
Share on other sites

Hi @wo997,

So, removing a constraint! That's an interesting task :) Apparently, I forgot an important function in the physics impostor class. the function exists, however, in both the physics engine and the physics plugins.

Here is a demo of how to remove a joint (until I fix it in a nicer way):

http://playground.babylonjs.com/#11OMIX#20

I hijacked your setKeys function (line 138). When you press "space" ballM loses all of its joints. You can decide which joints to filter, of course. I am using a brute-force-method here.

If you tell me the API is not the best, i would agree with you :) . I am also accessing private members here, due to the way I built the removeJoint function in the physics engine. You can keep a trace on all joints created and remove them as you wish, if you know the main impostor and connected impostor. 

Again - I will find a nicer way of doing that. The best would actually be a dispose function on the joint itself! No idea why I never implemented that... 

On my TODOs!

Link to comment
Share on other sites

@RaananW Thank you for that. The next thing I wanted to implement was making it crashing not when it touches something, but when the force is to high. To make that I will look for tiny differences of distance between connected objects. Is that a good way of thinking? When I finish this I will let you see the effect ;)

Link to comment
Share on other sites

I can simply create an array of distances between bodies right after running and then in each frame check if the distance has changed to much - that means the force also must be to high to keep the object in one piece, I will do it as quickly as possible ;)

Link to comment
Share on other sites

Just now, wo997 said:

Btw do you like my idea of creating something I call "rigid joint" (line 206 in code)? It combines 3 hinge joints to keep the objects stable in the same position and direction.

yes I do. that's only in case you need the motor. Otherwise, couldn't you use a compound impostor?

Link to comment
Share on other sites

you need to keep a reference to your created joints, this would be the easiest.

impostors and joints don't have IDs, they are independent objects that can be used however the developer wishes. So, when creating a joint, keep it referenced in an array / object of your choice.

having said that - those are javascript objects. you can add your own ID, or even tag them using Babylon's tagging system.

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