- Home /
Separate child rotation
Hi,
I'm moving an object using AddForce in a particular direction and rotating the transform using this:
var mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
Quaternion rot = Quaternion.LookRotation(thisTransform.position - mousePosition, Vector3.forward);
transform.rotation = rot;
transform.eulerAngles = new Vector3(0, 0, thisTransform.eulerAngles.z);
My object has a child object which moves with it. However, I'd like the child object to be in the same position as the parent object but have a different rotation that I can move separately. Is there a way to do this?
One idea I had was removing the child completely but I'm concerned that as these are both moved via physics, they could separate their positions.
Thanks for any help
Seems like it would be easiest to make both objects children of a new object that controls their position while the children each control their own rotation.
Apologies if I'm not understanding but would there not be the same issue present except with the parent object ins$$anonymous$$d?
Answer by Inok · Jun 28, 2015 at 08:27 PM
you can detach "children" and translate its position to position of "ex parent" by simply write few line of code:
Transform Parent_Tr;
Transform Child_Tr;
void Update()
{
Child_Tr.position = Parent_Tr.position;
}
But this work only if "ex children" not have own rigidbody.
Sorry, they both have rigid bodies but thanks for your reply.
You then can connect them by configurable joint, its most advanced.