Havoc: problems with parented meshes

In the following playground use WASD keys to navigate.
Press 1 to open/close sliding door.
Press 2 to open/close rotating door.
You can also push the box by running into it. Box collisions are logged into console.log.

a) When sliding door opens it creates the copy of the door behind (with some offset to the left).
b) Rotating door appears to be misaligned, it also opens incorrectly.
c) Box can not be pushed through open door. It still collides with physical bounding box of the corresponding door.

If you remove the PhysicsAggregate doors start to work normally except the fact that box now can be pushed through the closed door (which totally makes sense, because doors are not physical anymore).

The setup above worked just fine with Cannon. In Havoc it feels like the mesh and it’s physical collision box are totally out of sync when the mesh is parented. I also get very weird behavior when I try to attach PhysicsAggregate to stairs (several cubes different in size parented to a virtual transform node), but this worth a separate topic.

a): Unable to determine what creates the “copy of the door behind”
If it wasn’t for parenting, it wouldn’t have moved, but I think this is a bug related to parenting.
To unlock physics for movement, set disablePreStep to false, move it, and lock it again to get the physics that matches the movement.(PG did only disablePreStep is false)

What is the meaning of ‘a’

I misjudged the collision to collision as harvok’s physics.
Since the physics assigned to the child are not assigned to the parent, in reality the position of the door is only the location of the parent and does not match the physics of the child.


However, I think the pg above only broke the parenting system and is not a solution to the question.

Childcare in Babylon It seems to be a different process from Habok’s hinge and physics, and it is recommended to use child care using the hinge in a similar way.
Basically, values ​​such as shape and position of a physical body can only have values ​​with a given mesh, instance mesh, transform node, etc., so either of the following is sufficient.

  1. Childcare in Babylon is checked hovok’s enable then When parenting, the physical body value of the child is passed to the parent, and the child is changed to non-physical.
  2. Parenting is discouraged and hinges are used

but I think all the answers were a way to bypass rather than a solution.

Yeah, it’s just hiding the problem under the carpet. With such approach we have to leave all parents in (0,0,0) position, which is inconvenient. Also, it doesn’t work with rotating door. Also, it doesn’t work with more complex static objects, like these stairs: https://playground.babylonjs.com/#GZIEA0. When physics is disabled, it looks normal, and it worked more or less normal with Cannon. But PhysicsAggregate turns it into a brick submersed into the ground. There is definitely something wrong happening with internal variables.

I’m taking a look at that today.

@splash27 I’ve done some changes in this PR:

Parenting should be supported now. Let me know how it goes once the snapshot is available for testing.

1 Like

Sorry, my initial playground had poor parenting setup for rotating door, that’s why some misplacement oddities happened. I just forgot to position both hinge and rotatingDoor into correct positions before parenting.

But the problems didn’t go away.
If I first do positioning and parenting and only then I attach the physicsAggregate everything looks okay while it’s not moving. However if I try open a door it’s forcedly closed immediately (true for both doors). Overall, it looks like after physicsAggregate is assigned I can’t move object anymore, by changing its parent’s position, which was possible with Cannon.

The stairs look okay if physicsAggregate is assigned after all steps are positioned. So at least it works with static objects now. But there is another oddity. With BABYLON.PhysicsShapeType.BOX everything works as expected, but with BABYLON.PhysicsShapeType.MESH it doesn’t work at all. A cube can be pushed through the stairs.

@Cedric thank u for this great update. I think there is still a problem. If we don’t set position for the child mesh, it will automatically get the negative values of parent position, and it won’t be 0,0,0. Do you think is that an issue?

I’m listing all the various parenting cases this week and will continue dev with @carolhmj
This is a complex subject that can give a lot of regressions if not done seriously.
I’ll keep you posted.


Any updates so far?

Issue is still on our todo list. No update so far.

Hello! We have a draft PR for that: [Physics] Better handling of parented bodies by carolhmj · Pull Request #13914 · BabylonJS/Babylon.js (github.com) with just a few issues to go over (mostly the stability of the solution)

1 Like

Update: PR has been merged! It will be in the next release :smiley:


My PG still doesn’t work: https://playground.babylonjs.com/#4517EG#11.
When I try to move the parent, the child element with physics attached doesn’t move. It was possible with Cannon.

a) , b), c) is resolved


What is exactly not working on the PG?

@splash27 You have to use body.disablePreStep = false; to allow babylon-sided changes to affect the physics body (mesh rotation, position, etc)

Okay. It works now. Thank you so much.

I noticed one more oddity. Probably it’s not related to current parenting problem, but I started to see it on last release. If you will open browser console during my previous playground: https://playground.babylonjs.com/#4517EG#14 you will see two warnings:

Cannot read properties of undefined (reading 'rotationQuaternion')

Looks like they are caused by cloning walls:

let wall_4 = wall_1.clone("wall_4");


let wall_5 = wall_1.clone("wall_5");

It’s interesting, that those warnings are caused only by those two walls above.
const wall_2 = wall_1.clone("wall_2"); doesn’t lead to warning.

Why is this happening? Is it a problem? Can it be avoided?

It’s “just” warnings, so it should be ok to ignore it… as long as there’s no actual error thrown.
But possibly something to do with cloning a mesh with a physics body/aggregate?

Here i moved cloning up, before any aggregates are added and the warnings are gone…
I don’t know why it happens though :slight_smile:

1 Like

Thanks for bringing this to attention, it was indeed a bug in the way the cloning was done, it will be fixed by this PR: [Physics] Fix warning on copying a mesh with physics body by carolhmj · Pull Request #13951 · BabylonJS/Babylon.js (github.com) :slight_smile: