Allow Dynamic Transforms + Dynamic Collision Objects + Parent-Child Hierarchies == WEIRD STUFF

Hi,

I have a Defold 1.12.1 project, in which I experiment with 2D physics, and I noticed some dynamic collision objects just flying away, without any forces applied to them.

This behavior seems to happen for the collisions objects in game objects that are part of a parent-child hierarchy, but it seems to depend also on the position in the world. I can’t find any restrictions mentioned in the documentation, so I’m asuming this way of using collision objects is allowed.

Is this normal or is it an issue? Am I misunderstanding something?

I attached the project in which I see this behavior: physics_stuff.zip (1.3 KB)

Specifying a parent with a non-zero position and rotation is only allowed for static, kinematic, or trigger collision objects. For dynamic ones, this is not possible because the transformation (position and rotation) is transferred each frame from the physics engine to the game object’s transform in Defold. Parent transformations are not taken into account in this process.

Just accept this as a fact and don’t do this for dynamic collision objects.

1 Like

I’m not specialist here, but I’ve played a bit with your project. It looks like the “offset” between the parent object position and the world’s center is applied as force to the child collision object. If it’s positive or negative position (x or y) it changes direction.

You can test that by changing “go1_ok” position by 1 pixel in any direction and you will see it also will fly away but slower. It was ok only becouse it’s at 0x 0y.

If the “offset” is too big the force or whathever is happening is so fast that it also ignores collission with static objects.

“go1_problem” and “go2_problem” look like the same thing just the sprite is not attached to the moving object (the go with the collisionobject).


physics_stuff_dirty.zip (2.2 KB)

It looks like a bug or just is not expected to nest go with collision objects.

1 Like

Ahh that explains it!

But indeed there is no info on that in the docs. Maybe a warning will be helpful.

1 Like

If I understand correctly, the documentation for Allow Dynamic Transforms says that, in case this option is enabled, a game object that has a dynamic collisionobject component can have it’s transform be modified also “kinematically”, not only by the physics simulation.

Given this, and the fact that a child game object is just a particular case of a parent game object(transform of the object is obtained by applying multiple transforms), tells me that child game objects could have their transform be modified also “kinematically”, not only by the physics simulation.

I don’t see why child objects are a special case when handling Allow Dynamic Transforms. Is there something wrong in my reasoning?

Edit: I think I’m starting to get it. The physics engine applies the transforme due to physics simulation to the world transform of the child game object, not to the transform relative to the parent, and then copies the new resulted transform in the transform of the child relative to the parent. This means that physics simulation replaces the child transform with the parent + child transform. And in doing so each frame, the child game object distances from the parent game object.

Edit2: Also, this explains why it works in the case the parent transform has no offset and no rotation. In this case the transform of the child relative to the parent is the same with the transform of the child relative to the world.

Now, the question is why is the physics engine applying the transform to the world transform of the child game object instead of applying it to the transform relative to the parent ? Is this intended or is it a bug ?

Physics engines normally doesn’t have a notion of such a scene graph with parent-child relationships. It applies the forces on the object, where it is currently at. This is why this setup is not recommended, as it’s hard to reason about.

Ok, so the physics engine receives the world transform of a child game object, and returns a modified version of that. Isn’t it possible to take the difference between the original world transforms and the world transform modified by the physics engine and then apply this difference to the transform of the chilg game object( the transform relative to the parent) ?

Just a clarification, initially I said this behaviour happens only when enabling Allow Dynamic Transforms but actually even when disabled there are still some weird behaviors but they look different.

It is not recommended to have a dynamic collision object on a game object which is not a root object in the scene graph. Do not add such objects as child game objects!

1 Like

I think this scenario shouldn’t be allowed by the engine or the IDE. Allowing it can lead to hard to debug scenarios, especially because there are cases in which nothing noticeable happens so the problem can be latent in some projects.