What transform needs to be set to Parent so that Child’s transform would match Target’s transform? Preferably need to get Parent’s global transform from Target’s and Child’s global transform. Would appreciate any help. Linear algebra sometimes is hard.
No algebra needed. If parent transform equals child then
Parent.global_transform = Target.global_transform
If you don’t care what parent is
Child.global_transform = Target.global_transform
If you want the child on the target but the parent offset? I think you have an hierarchy issue cause that is a little strange. Why not reorder them to be easy like above? but it’s also very easy. It’s linear.
Yeah that would have been really easy problem if it was just like you described. But the thing is that I need to keep Child’s local Transform. I mean that the rotation, scale and position relations between Child and Parent should be the same. In your code Parent’s basis does not change, therefore the previous relations of rotations of Parent and Child are ignored.
I came up with the next code that works pretty well:
But I still need to get the same result with only global transforms of Target and Child. Because Child maybe not the direct child of Parent. I seek for general solution for such situation.
I think you have an hierarchy issue cause that is a little strange. Why not reorder them to be easy like above?
Oh well. I really would love to make them simply not related. But in project I work on they are parts of single object where Child defines offset of Parent connection to other similar objects. It mostly made so player and game designer have more freedom in making those objects. But to be honest this system brings me headache, and I’m not really willing to rewrite existing code base.
I think my approach would work as long as you have references to the child and parent. It would also save you the computation of computing an inverse affine transform, matrix multiplication.
Just need to rearrange it a little.
# set transform
Parent.global_transform = Target.global_transform
# relative difference
var target_child_diff : vector2 = Target.global_position - Child.global_position
# position
Parent.global_position += target_child_diff
Well this just sets transform of the Parent to be equal to Targets transform which is not what I need. I need to set Child’s global transform to Target’s global transform.
I have no idea how to make it work in 3D. You can’t really represent 3D rotation with just one angle and you can’t really just subtract one basis from another. So this doesn’t makes much sense in 3D as far as I know.
as to how to use it? it’s quite “complex”
basically you add this as a child of your target transform
set the remote_path variable of this RemoteTransform3d node to the Node you want to make the Node follow the Target
so when the Target node move/rotate, the Node should follow
i might mixed up the way to set it up, either that or the other way around.