Skip to content

Instantly share code, notes, and snippets.

@daseyb
Created November 30, 2018 18:15
Show Gist options
  • Save daseyb/fa8350497283e851c93e9e9ef8d49aee to your computer and use it in GitHub Desktop.
Save daseyb/fa8350497283e851c93e9e9ef8d49aee to your computer and use it in GitHub Desktop.
using UnityEngine;
using System.Collections;
public class Mirror : MonoBehaviour
{
public Vector3 ReflectPosition(Transform originalObject)
{
Vector3 localOriginal = transform.InverseTransformPoint(originalObject.position);
Vector3 localReflected = Vector3.Reflect(localOriginal, Vector3.forward);
var reflectedPosition = transform.TransformPoint(localReflected);
return reflectedPosition;
}
public Quaternion ReflectRotation(Transform originalObject)
{
Quaternion rotation = Quaternion.Inverse(transform.rotation) * originalObject.rotation;
Vector3 axis;
float angle;
rotation.ToAngleAxis(out angle, out axis);
axis = Vector3.Reflect(axis, Vector3.forward);
return transform.rotation * Quaternion.AngleAxis(angle, -axis);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment