# Adding a child transform with its own collider

**URL:** <https://forum.castle-engine.io/t/adding-a-child-transform-with-its-own-collider/1506>\
**Category:** Uncategorized\
**Created:** [January 26, 2025, 8:45pm UTC](https://forum.castle-engine.io/t/adding-a-child-transform-with-its-own-collider/1506 "2025-01-26T20:45:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![NiunioMartinez](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/niuniomartinez/32/2232_2.png) [@NiunioMartinez](https://forum.castle-engine.io/u/NiunioMartinez)\
**Post date:** [January 26, 2025, 8:45pm UTC](https://forum.castle-engine.io/t/adding-a-child-transform-with-its-own-collider/1506/1 "2025-01-26T20:45:00Z")

</div>

I’ve added a child node to my enemy to use it as _attacking area_ See the next screenshot:

 ![The zombi with his child.](https://forum.castle-engine.io/uploads/default/original/2X/8/8b4e749284d775b7ddb5abbc91264df8dd3c6b16.png)

But in game, the child doesn’t move with its parent as you see in the next screenshot (I’ve changed the `TCastleTransform` by a `TCastleBox`):

 ![The zombi leaving his child behind.](https://forum.castle-engine.io/uploads/default/original/2X/a/a58c5473aeac599607e62a8eadb8f5a3be83a7c2.png)

If I remove the child’s collider and rigidbody it works, but then the zombi’s collider seems to be bigger because the child cube pushes the player (?!).

Is it a bug or am I doing something wrong?

---

<div class="post-metadata">

**Author:** ![michalis](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/michalis/32/3_2.png) [@michalis](https://forum.castle-engine.io/u/michalis)\
**Post date:** [January 27, 2025, 9:45am UTC](https://forum.castle-engine.io/t/adding-a-child-transform-with-its-own-collider/1506/2 "2025-01-27T09:45:15Z")

</div>

Hm, this definitely seems like a bug – can you submit a testcase for me to play around and reproduce / fix?

To be clear, it should work as you expect – moving the `TCastleTransform` should move the children, along with children’s colliders naturally. I did use this technique many times (like in `examples/mobile/two_cars/` where cars, with their colliders, move).

Note that we had a bug around this in earlier engine versions, but it was fixed around August 2024 (around [this post](https://forum.castle-engine.io/t/i-cant-rotate-this-box/1311/2)). So if you’re using an older version of the engine, please upgrade and retest.

> [@NiunioMartinez](#):
>
> If I remove the child’s collider and rigidbody it works, but then the zombi’s collider seems to be bigger because the child cube pushes the player (?!).

I don’t understand this issue clearly here (I don’t see zombie collider on the 1st screenshot), but feel welcome to submit a testcase showing it too.

---

<div class="post-metadata">

**Author:** ![NiunioMartinez](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/niuniomartinez/32/2232_2.png) [@NiunioMartinez](https://forum.castle-engine.io/u/NiunioMartinez)\
**Post date:** [January 28, 2025, 12:08pm UTC](https://forum.castle-engine.io/t/adding-a-child-transform-with-its-own-collider/1506/3 "2025-01-28T12:08:39Z")

</div>

I’ve updated to yesterday’s snapshot and it still happens.

I’ve made a small example that reproduces the issue. I’ve uploaded [here](https://allegro-pas.sourceforge.net/tutorials/vivace/src/child-test.zip)\*. I explain things in the `README.md` file so please read it.

* * *

[\*] It was the first place I’ve found. If the link doesn’t work assume I’ve clean the website. 😛

---

<div class="post-metadata">

**Author:** ![NiunioMartinez](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/niuniomartinez/32/2232_2.png) [@NiunioMartinez](https://forum.castle-engine.io/u/NiunioMartinez)\
**Post date:** [February 6, 2025, 1:22pm UTC](https://forum.castle-engine.io/t/adding-a-child-transform-with-its-own-collider/1506/4 "2025-02-06T13:22:09Z")

</div>

I think I’ve found a possible culprit: the Kraft physics engine. I’ll try to explain.

In my code I use `LinearVelocity` to move the characters as `Translation` didn’t seem to work. I use a _finite state machine_ so when moving or jumping I update `LinearVelocity` in each `Update` and I set it to zero when it enters in the `Idle` state but not update it.

When I’ve added rotation I found an issue: if I update `Direction` in each `Update`, even if it doesn’t change, the character doesn’t move smoothly but its speed is random as if the ground were wrinkled and it hits when sliding. So I added a check to know if direction changed before the update and now characters move as they should.

My guess is that everytime `Direction` is assigned, Kraft updates it’s momentum or velocity to zero even if it shouldn’t change. Also everytime a transform changes it’s physics state, Kraft updates its childs physics state.

Diving a little in the code I’ve found that CGE checks if rotation changes before to assign the new one; maybe `RotationFromDirectionUp` introduces some round-errors that makes `PerfectlyEquals` to _fail_ when assigning the rotation but those round-errors are so small after applying Kraft physics that rotation doesn’t change?

Does it has sense?
