fort Posted November 13, 2017 Share Posted November 13, 2017 Hey! I think this is going to be another one of those, "oh right, it's this" sort of questions, but after tinkering with it for far too long, I figured I'd tap into the brain trust that is this forum. I have a cylinder nested inside Epcot Center an icosphere. Both of these will have a mass of zero. Here's the PG: https://www.babylonjs-playground.com/#UGTGRU. Move your mouse over the icosphere—the cylinder positions/rotates along the picked facet/normal. Click the icosphere to enable physics and set the impostors starting with the cylinder, then the icosphere. Notice that the icosphere's rotation jumps Here's what I'm wondering: Since these things aren't supposed to move in my scene (since the mass === 0), how could I go about setting up these physics impostors in such a way that would preserve the rotation/position of the icosphere and the cylinder at the moment it's clicked? Also, what if the impostor hierarchy is three+ levels deep? Also wondering: Could the icosphere and cylinder (parent/child) impostors have different restitution and friction values? Thanks!! Quote Link to comment Share on other sites More sharing options...
RaananW Posted November 13, 2017 Share Posted November 13, 2017 Hi fort! Love your questions Babylon's parent hierarchy should be discussed in depth. I will finish the physics documentation until 3.1 will be released and I hope those questions will be answered in full in those docs. About your issue - 1) When setting two impostors ,one of them being a parent of the other, the two meshes will create a compound, which means - a single body for the physics engine, with both meshes "merged" together. From this moment, only the parent object can be controlled by the physics engine, the rest of the impostors are not being taken into account. The mass of all child impostors is being accumulated, but the rest (restitution, friction) is being set solely on the parent level. 2) There is a new option that was introduced in 3.1: ignoreParent: true (in the physics impostor options). This will create an impostor of a child mesh irgnoring the fact that it has a parent. The catch here, however, is that the parent cannot have its own impostor. So, in your case, it will not work correctly. 3) You are enabling physics and creating new impostors with every click on the meshes. Try setting the impostors once, and changing them when needed, instead of recreating them. It will be much more stable. If you do, however, want to recreate the impostors every time, don'T forget to dispose of the old ones (impostor.dispose()), otherwise the physics engine will still have them as a reference (Garbage collection will not work, and they will not be disposed by themselves). 4) Setting the rotation (Quaternion!!) and the position of a mesh with an already-existing impostor will update the impostor's position as well. So you should simply change the transformation of the mesh. Expect some strange behavior if you move an impostor INSIDE a different impostor (my guess - it will be shot right out very very fast), but in general, it should work without a problem. I ho9pe I answered everything! fort 1 Quote Link to comment Share on other sites More sharing options...
fort Posted December 3, 2017 Author Share Posted December 3, 2017 Thanks, @RaananW—that clears things up nicely. RaananW 1 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.