Hi,
I’m trying to write a script to be added to a game object A that replicates the deltas (between frames) of local position and local rotation of another game object B.
For example when B moves to its right by say 1 unit, A moves to its right by 1 unit.
The same thing for rotation: when B rotates by 10 degrees on its left, A rotates by 10 degrees on its left.
In the script I keep the local position and rotation of the object in the previous frame and calculate the deltas in the current frame, I managed to make the rotation work, but I’m struggling with replicating the position.
public class MirrorLocalMovement : MonoBehaviour
{
public Transform target;
private Vector3 prevLocalPos;
private Quaternion prevLocalRot;
private bool firstUpdate = true;
private void Update()
{
if (firstUpdate)
{
firstUpdate = false;
}
else
{
transform.Rotate((target.localRotation * Quaternion.Inverse(prevLocalRot)).eulerAngles);
// Translation?
}
prevLocalPos = target.localPosition;
prevLocalRot = target.localRotation;
}
}
I tried with transform.Translate and transform.InverseTransformDirection but with no success.
How can I replicate the translation in local space between the two objects?
Thank you in advance