#How to fix a child entity's transform fixed while parent entity is scaling/rotating

6 messages · Page 1 of 1 (latest)

onyx palm
#

I have a parent entity that will move around and rotate or scale based on external forces. I want to fixate its child entity to a relative translation to the parent's translation, but without it's scale or rotation.

I'm thinking about updating the child entity's transform based on the parent's global transform inverse. But I found I suck badly at the maths and can't figure out the correct operation to do. Also I don't know what schedule to run the update system to make sure everything is aligned properly.

upbeat lotus
#

I would consider whether they really need to be parent/child. What if you just figure out the relative position you need (by using the "parent's" GlobalTransform::transform_point, or maybe the inverse of that, not sure), then just set that child's position to that?

#

Note you would probably need to schedule it in PostUpdate before the TransformSystem::TransformPropagate and use TransformHelper instead of GlobalTransform directly

#

If you're dead set on having the child actually be a child, I think you should just be able to set the child to have its rotation be the inverse of the parent's GlobalTransform rotation and same for the scale

#

But that would still require you to use TransformHelper, so it stays in sync

onyx palm
#

Thank you @upbeat lotus ! I ended up not spawning the entity as child because it's much simpler to deal with transform configuration. I have to manually despawn the entity when the other entity despawn, which isn't too bad.