- Home /
How to rotate parent only without affecting children?
I have child objects which I want to the freeze their rotation, but be affected by the parents movement.
How do I go about this?
Answer by pmerilainen · May 22, 2019 at 03:01 PM
I think the easiest way is not to use hierarchy at all. Just use a script in each of the follower that keeps their distances at fixed offset from a transform (player in this case).
Answer by hederson_3_12 · May 22, 2019 at 01:26 PM
In the same function, you rotate the parent you should have the reference to his child's and rotate them the same amount as the father but in negative but why you need to do that?
I have four child objects of my player. These objects are targets for the camera, when the player is in certain states I want the camera to move to one of these objects. I want these children to maintain their position, move with the player, but not rotate. Hope this helps.
Here are my rotate functions, how should I proceed?
void RotateLeft()
{
transform.Rotate(Vector3.forward * rotatespeed);
z += Time.unscaledDeltaTime * -rotatespeed;
}
void RotateRight()
{
transform.Rotate(Vector3.back * rotatespeed);
z += Time.unscaledDeltaTime * -rotatespeed;
}
If I understand what the guy above has said, you could adapt these to take a transform being passed in. then where you call them pass in the player transform. then immediately after that have a foreach that will do the children in the opposite direction
so:
RotateLeft(this.transform);
foreach (Transform t in this.transform)
{
RotateRight(t);
}
I think that is how you get the transform children. I have not tested this. You could also give them a kinematic rigid body and lock rotation. That might work. Or their own script which constantly sets the rotation to their start/specified rotation.
I'm not the best at Unity so I'm struggling to understand what you suggested first. I've tried using the rigid body route you suggested earlier, but as fair I can tell it doesn't work. I haven't tried what you suggested last, but I'm not sure how I go about that.
Answer by CruS · May 22, 2019 at 02:15 PM
Perhaps this will help?
https://docs.unity3d.com/2019.2/Documentation/Manual/class-RotationConstraint.html
"Freeze Rotation Axes"
Your answer
![](https://koobas.hobune.stream/wayback/20220612201855im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Flip the player with arm rotation 2 Answers
Rotate objects by mouse 2 Answers
problem with rotation 2D 1 Answer
,Rotating a 2D sprite with Input 0 Answers