wo997 Posted January 22, 2017 Author Share Posted January 22, 2017 Hmm... is that something about making the world as object and using it in code? It will be hard to do for me, there is lots of stuff do to and I can't find any tutorial about it. Quote Link to comment Share on other sites More sharing options...
wo997 Posted January 23, 2017 Author Share Posted January 23, 2017 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...)? Quote Link to comment Share on other sites More sharing options...
Wingnut Posted January 23, 2017 Share Posted January 23, 2017 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. Quote Link to comment Share on other sites More sharing options...
Raggar Posted January 23, 2017 Share Posted January 23, 2017 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. Quote Link to comment Share on other sites More sharing options...
wo997 Posted January 23, 2017 Author Share Posted January 23, 2017 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. Quote Link to comment Share on other sites More sharing options...
Raggar Posted January 23, 2017 Share Posted January 23, 2017 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. Quote Link to comment Share on other sites More sharing options...
wo997 Posted January 23, 2017 Author Share Posted January 23, 2017 @Raggar @Wingnut I found this (below) and I will try to do it on my own Quote Link to comment Share on other sites More sharing options...
wo997 Posted January 23, 2017 Author Share Posted January 23, 2017 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. Quote Link to comment Share on other sites More sharing options...
Raggar Posted January 23, 2017 Share Posted January 23, 2017 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? wo997 1 Quote Link to comment Share on other sites More sharing options...
wo997 Posted January 23, 2017 Author Share Posted January 23, 2017 @Raggar I tried and everything is alright :/ I have trouble with what I should call the function for, for a body or a constraint? if for a constraint then how can I do this? Quote Link to comment Share on other sites More sharing options...
RaananW Posted January 25, 2017 Share Posted January 25, 2017 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! wo997 1 Quote Link to comment Share on other sites More sharing options...
RaananW Posted January 25, 2017 Share Posted January 25, 2017 Oh, BTW - i LOVE your demo. Carry on! Quote Link to comment Share on other sites More sharing options...
wo997 Posted January 25, 2017 Author Share Posted January 25, 2017 @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 Quote Link to comment Share on other sites More sharing options...
RaananW Posted January 25, 2017 Share Posted January 25, 2017 hey, I am not sure what force you are referring to, so I can't really help. You are tracking many variables yourself, so you could always have a combination of those, you can check for velocities of each part, so many options Would love to see the final result. Quote Link to comment Share on other sites More sharing options...
Raggar Posted January 25, 2017 Share Posted January 25, 2017 I'm not entirely sure what you mean either. Do you mean measure the distance between two constrained bodies, or something like .addEventListener('collide', function(body){ if(body.velocity > 10){ //Remove joints/Crash etc. } }); ? Quote Link to comment Share on other sites More sharing options...
wo997 Posted January 25, 2017 Author Share Posted January 25, 2017 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 Quote Link to comment Share on other sites More sharing options...
wo997 Posted January 25, 2017 Author Share Posted January 25, 2017 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. Quote Link to comment Share on other sites More sharing options...
RaananW Posted January 25, 2017 Share Posted January 25, 2017 I just read what I wrote and it made no sense to me, so - old me was silly. if it is about collisions and force during a collision checking the velocity will be the best (IMO). if it is about "going too fast", then you can track the variables changed by the keyboard events. Quote Link to comment Share on other sites More sharing options...
RaananW Posted January 25, 2017 Share Posted January 25, 2017 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? Quote Link to comment Share on other sites More sharing options...
wo997 Posted January 25, 2017 Author Share Posted January 25, 2017 1 minute ago, RaananW said: yes I do. that's only in case you need the motor. Otherwise, couldn't you use a compound impostor? Yes, I think I should, but it's to much for me for now, I will finish some basics first. Quote Link to comment Share on other sites More sharing options...
wo997 Posted January 25, 2017 Author Share Posted January 25, 2017 @RaananW Just a quick question, how do I acces each of the joints separatelly? I tried _joints[0] but I can't just type forEach, what else should go here? And I think it may be hard to use ID if I remove them, disabling would be a better option, do you see the point? Quote Link to comment Share on other sites More sharing options...
RaananW Posted January 25, 2017 Share Posted January 25, 2017 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. Quote Link to comment Share on other sites More sharing options...
wo997 Posted January 25, 2017 Author Share Posted January 25, 2017 @RaananW Just imagine how my face looked when it finally worked, hahahahaha Quote Link to comment Share on other sites More sharing options...
wo997 Posted January 25, 2017 Author Share Posted January 25, 2017 I've got some progress, press space when flying to crash http://playground.babylonjs.com/#11OMIX#21 iiceman, Raggar and RaananW 3 Quote Link to comment Share on other sites More sharing options...
wo997 Posted January 26, 2017 Author Share Posted January 26, 2017 @RaananW @Raggar @iiceman @Wingnut Try bumping into the wall or a "house" with high speed. I think the final effect is pretty ok. Am I the first who made crashing in Babylon.js? Sorry if you take it as spam. http://playground.babylonjs.com/#11OMIX#22 Wingnut and iiceman 2 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.