I want to create a rather simple program. I just want to have two objects on the screen (for testing I am just using two pictures of boxes) mirror movements. So when I use the keyboard to move one object, the other object mirrors the movement. For example, if I move one object right, the other object would move left. But if I move one object up, the other object would also move up.
I have tried a couple of different approaches but can’t seem to get anywhere even remotely productive. Can anyone please steer me in the right direction?
If you need the actual inputs mirroring, then depending on how you move the object, determine which axis you want it to be mirrored.
E.g. apply movement on -transform.right instead of transform.right to mirror movement on X axis.
And apply the rest of the movement as is for the YZ axis.
You can simply use Vector3.LerpUnclamped. You set object b position twice the distance from object a to a mirror point. You could also add an offset in there if you don’t want it perfectly mirrored.
using UnityEngine;
public class MirrorObject : MonoBehaviour
{
public Transform ObjA;
public Transform ObjB;
public Transform MirrorPoint;
private void Update()
{
ObjB.position = Vector3.LerpUnclamped(ObjA.position, MirrorPoint.position, 2f);
}
}
1 Like
Thank you so much, this seems perfect. Admittedly I will need to do a little research on the concept of Lerp to make sure that I fully understand the how and why this works, but it is perfect for getting started.