- Home /
Rotation problem
Hello!
A bit complicated question. I have a problem with rotations. In 3D space there are 2 objects. One of them is parent, and another one is child (like on 1st picture, a rectangle). If we turn parent by axis Y, then child should turn follow parent and stay face to face with parent.
And also if we parent by Axis X (like on 2nd picture), then child should move up and down, but at the same time child should not turn by axis X. Which basically means child should not be looking at parent, just move up or down.
I have already used Quaternion.Inverse(parent.transform.rotation) - in that case rotation X work properly, but rotation Y rotates around its axis, which we DO NOT want.
It's quite complicated, hopefully you understand through my broken english.
Ordinarily, I would do this kind of thing without parenting. Is the parent-child relationship necessary, or is it simply for movement?
Answer by Arycama · Apr 24, 2017 at 11:19 AM
A child transform looking at it's parent will always continue to look at it if the parent is rotated, it is the purpose of parent-child transform relationships.
If you want an object to follow a parent object's position, but not rotation and scale, then do not use a parent-child relationship. Use a script to position the "child" object based on the parents position, and transform.forward.
A script may look like this:
class FollowObjectRotation : MonoBehaviour
{
// Assign this to the "parent" object, in the inspector
public Transform parent;
// Distance which you want the child to remain from the parent
public float distance;
void Update()
{
transform.position = parent.position + parent.transform.forward * distance;
}
}
Your answer
Follow this Question
Related Questions
Set Rotation on Multiple Axis 1 Answer
Calculating where vertices would be without rotation 1 Answer
Locking rotation makes object spin 0 Answers
Quaternion LookRotation issue 0 Answers