I am trying to write a script that allow me to rotate an object, treating a dynamically moving child as the pivot.
This is to allow the parent to rotate, while allowing the child to feel as though the rotation was centered on itself.
My current technique is to create a grandparent above the parent, control positional offsets on the grandparent and parent, and then rotate the grandparent when needed. The Grandparent and child should have the same world positions, so that rotating on the child pivot is the same as rotating on the grandparent pivot.
`public class TrackedPivotPoint : MonoBehaviour
{
public Transform parent, child;
// Update is called once per frame
void Update ()
{
parent.localPosition = -child.localPosition;
transform.position = child.localPosition;
}
}`
This script manages the offsets perfectly... as long as the grandparent isn't rotated, which is kind of the point.
I'm not sure what it is im not taking into account at this point.
Any tips where I'm going wrong would be appreciated.
↧