Jump to content

Rotation of nested physics impostors


fort
 Share

Recommended Posts

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.

  1. Move your mouse over the icosphere—the cylinder positions/rotates along the picked facet/normal.
  2. Click the icosphere to enable physics and set the impostors starting with the cylinder, then the icosphere.
  3. 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!!

Link to comment
Share on other sites

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!

 

Link to comment
Share on other sites

  • 3 weeks later...

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