- Home /
how to do full child-parent transformation, without parenting?
Hello,
i've searched the forums and answers for this, and even though i found some close matters i couldn't find it, and it must all be down to math/geometry. i don't want to parent a gameobject to another one, because i want to avoid compound colliders creation (how i wish there was an option to turn them off!) so i must do the rotation and position of the child manually from its parent.
function LateUpdate(){
transform.position = parentPiece.transform.position + localPosition;
transform.rotation = parentPiece.transform.rotation * localRotation;
}
but i know i'm missing a bit in the position. because when i rotate the "parent" object the child does not follow in the place it should. it changes the position/rotation locally and it's not really behaving like a child.
so what do i have to add at the position part to make it look right? any equations for this? thank you!
GameObject hierarchies and compound colliders are totally unrelated. I don't quite understand your problem.
oh wait, do you mean that the problem with the colliders is that when parenting, the child's collider will work as a collider for the parent?
Yes exactly this Steven and Graham, haven't you ever stumbled upon it? http://docs.unity3d.com/Documentation/Components/class-Rigidbody.html scroll down to compound colliders and you'll see what i'm talking about. i have parents and children with colliders, and all i end up with is a compound collider! so to avoid this i have to make my "children" game objects follow the "parent" without actually parenting them...
well yeah, ofcourse we know about compound colliders, it just wasn't very clear first what the problem exactly was, since there isn't really much context
A compound collider is just a bunch of game objects in a hierarchy that have collider components attached. I don't think that hierarchies cause compound colliders to be created. If your hierarchy doesn't need colliders at every node, just delete the colliders from the game objects. (I have no idea how you are using physics, or what your hierarchy is, even. So this might not be possible in your case.)
Answer by Steven-1 · Mar 05, 2013 at 12:45 PM
Well what you're doing is definately wrong, but I don't immediately know The correct calculations.
But you could just use a workaround though: Create a new empty gameobject with identical transform to the wannabe child, make this the child instead. Then in a Late Update you just set the wannabee child's transformation equal to the new emptychild. Ofcourse, that's assuming you don't want to change the child's local position/rotation.
Edit: or just use Transform.TransformPoint()
transform.position = parentPiece.transform.TransformPoint(localPosition);
http://docs.unity3d.com/Documentation/ScriptReference/Transform.TransformPoint.html
great idea! actually i'll child the empty gameobjects to the parent and then set rotation and position of the indirect children almost like i did before
function LateUpdate(){
transform.position = parentGO.transform.position;
transform.rotation = parentGO.transform.rotation;
}
That's exactly what I meant.
(my second solution is cleaner though)
while searching for solution I came to this Q and digging more in to it I found this witch pointed me to Transform.RotateAround
anyway +1 to both Q && A
Answer by thedetective456 · Sep 10, 2021 at 11:58 AM
Hey, I actually found a cool gut repo few hours ago : https://github.com/pointcache/Unity-3d-Constraints
Why not use default constraints? Cause they update somewhere after animator IK and late update in a loop called "PreLateUpdate", which is a problem for Animator IK. It forces you to use the "Animation Rigging".
Not anymore, have fun!