Created
November 30, 2018 18:15
-
-
Save daseyb/fa8350497283e851c93e9e9ef8d49aee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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