hey guys, I have a question about parent rotation independent of child. I have a object A which rotates 360 degree y axis using localEulerAngles, when ever a object B touch object A, A makes B its parent. Now object A moves with B ( in circle) which is absolutely right, but now object B transforms itself to another shape and changes its rotation as well. Is there any solution I can change rotation of parent independently without affecting angles and rotation of child ??
The purpose of parent/child connection is to have each child dependent of its parent.
So either don’t connect them like @Fattie suggested. Or if it is a special operation you can temporarily unparent the child, modify the parent and reparent:
// Get all direct children
Transform[] children = new Transform[this.transform.childCount];
int i = 0;
foreach(Transform child in this.transform)
{
children[i++] = child;
}
// Detach
this.transform.DetachChildren();
// Change parent transform
this.transform.position = v3NewPosition;
// Reparent
foreach(Transform child in children)
{
child.parent = this.transform;
}
children = null;
I found a solution for my case, I wanted to rotate ‘A’ without rotating ‘B’:
- Parent A
- Child B
Solution:
- Parent C
- Child A
- Child B
What I did was create a new object C that is the parent of A and B, now with the script on object C I can choose whether I want to rotate only child A without affecting object B or vice versa.