kavsnzre Posted June 5, 2016 Share Posted June 5, 2016 Hello everyone! I'm trying to understand how to use physics engine in Babylon. I understood the basical instructions and all about this is clear. But I've a serious problem that I'll explain with an example. I've a cube that falls onto a plane having a fixed angular velocity, here is the playground: http://www.babylonjs-playground.com/#UQNWL Obviously: if I set the frictions with very large values then the box will very fastly loose its angular velocty when it'll fall onto the plane if I set both the frictions values equals to 0 then the box will never stop and will rotate onto the plane forever... But...what if I want that the cube will stop in 5.76746 seconds? In this case, which values I have to put into the "friction" variables? Maybe I've the answer: I have to know the physical equations used by cannon.js, then I've to solve my physics exercise, and then I've to put the correct values into the "friction" variables. If I'm right, where can I find the EXACT equations used by cannon.js? Is there a sort of manual? Or I've to deduce them from the code? Is there another way to solve the problem? Thank you so much! Best regards. Quote Link to comment Share on other sites More sharing options...
JohnK Posted June 5, 2016 Share Posted June 5, 2016 Welcome kavsnzre as a non expert in cannon physics I can suggest only trial and error but am sure the experts will give you a better answer. To help the experts answer your question would you put the relevant parts of your code into a playground. This way the lovely people on the forum can make changes and suggestions and be even more helpful. kavsnzre and Samuel Girardin 2 Quote Link to comment Share on other sites More sharing options...
kavsnzre Posted June 5, 2016 Author Share Posted June 5, 2016 Hy JohnK, thak you so much for the tips! I created the playground and edited my question. Is it ok now? Thank you again, best regards. JohnK 1 Quote Link to comment Share on other sites More sharing options...
Wingnut Posted June 6, 2016 Share Posted June 6, 2016 Hi @kavsnzre, welcome to the forum. Here's some links for the third party Cannon.js physics engine. Hope this helps. https://github.com/schteppe/cannon.js/tree/master/src/equations http://schteppe.github.io/cannon.js/docs/classes/FrictionEquation.html You might see a method in mainline Cannon.js code: this.updateFriction(timeStep); and it is likely related to https://github.com/BabylonJS/Babylon.js/blob/master/src/Physics/babylon.physicsEngine.js#L99 BJS interfaces with the third party CannonJS engine... via 3-4 various objects. They can all be seen here... https://github.com/BabylonJS/Babylon.js/tree/master/src/Physics And I imagine the timestep is related to frames per second and thus affected by platform performance, but that's way over my head. Just for fun, I made another playground where spin lasts about 5 secs (trial and error method as @JohnK mentioned). Your spin duration may vary. @schteppe DOES have a forum membership here, but it is unclear how often he visits. Good luck, keep us posted. kavsnzre 1 Quote Link to comment Share on other sites More sharing options...
kavsnzre Posted June 6, 2016 Author Share Posted June 6, 2016 @Wingnut Thank you for your answer! I'll keep you posted. Bye. Wingnut 1 Quote Link to comment Share on other sites More sharing options...
schteppe Posted June 6, 2016 Share Posted June 6, 2016 Thanks for the mention @Wingnut! I don't hang out here every day but sometimes it happens @kavsnzre you can read about the equations in this PDF. http://www8.cs.umu.se/kurser/5DV058/VT15/lectures/SPOOKlabnotes.pdf I hate to break it to you, but the equations used in game physics are not exact. They usually use iterative solvers that can solve the equations more and more precise depending on how much CPU power you are willing to pay. Also, the equation are only solvable "in one direction", you can't really input a time value and expect the engine to give you the friction constant. It's optimized to only output game object transforms. What you CAN do is run the simulation many times until you find a value for the friction that matches your time value. I hope this helps kavsnzre, JohnK and Wingnut 3 Quote Link to comment Share on other sites More sharing options...
kavsnzre Posted June 6, 2016 Author Share Posted June 6, 2016 Very clear! Thank you very much @schteppe! 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.