Hi!
I am trying to figure out efficient way to attach and detach objects in run time. It is actually easy like this
childTransform.parent = parent.Transform; to parent and childTransform.parent = null to unparent the object, but that is only that case if you are using pivot points of both objects.
I have a situation where i have object with multiple attach points. So one object has its pivot point but also should have other points where child object will be attached. Also child object, if they have multiple attach points, beside their pivot point they should have more attach points.
I started using dummy objects for this. and here is how hiearachy looks
Parent I (RigidBody)
Object's Mess (Mesh and Collider)
Connections (Empty GameObject as a Container)
AttachPoint I (Empty GameObject - only Transform)
AttachPoint II (Empty GameObject - only Transform)
Child (RigidBody)
Object's Mess (Mesh and Collider)
Connections (Empty GameObject as a Container)
AttachPoint to Parent I (Empty GameObject - only Transform)
So when I am attaching child to parent i do it like this:
child.GetComponent<RigidBody>().IsKinematic = false; //I want kinematic RigidBody while object is attached
child.transform.position = parentAttachPointI.transform.position //this sets objects position not taking child attach point into account
child.rotation = parentAttachPoint.rotation;
child.parent = parentAttachPoint;
Everything works ok, except the fact that I can’t figure out how to take attach points into account? The children are attached and detached just fine but on wrong position (using objects transform not dummy objects)
If i use dummy objects, because of the nature of the hierarchy. they are unparented and parent to the other object but nothing happens since they are empty
Does any of this makes sense?