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. https://playground.babylonjs.com/#4517EG#3
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) https://playground.babylonjs.com/#4517EG#5
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.
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.
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.
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. https://playground.babylonjs.com/#4517EG#11.
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. https://playground.babylonjs.com/#GZIEA0#1
@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 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?