I’m working on a a similar mechanic to portals and I’m having some issues when the portals are not in the same angle. Basicly, once an object enters through the first portal, a copy is created in the second portal giving the illusion that is passes through. I’m having some issues when the portals have a different rotation. Here’s a quick picture of the issue.
Clearly The Quaternion i use to make the rotation in the mouvement is wrong, the Quaternion i use right now is this :
Quaternion portalRotation =
Quaternion.FromToRotation(LinkedPortal.transform.parent.rotation.eulerAngles,
transform.parent.rotation.eulerAngles);
This code is on the portal itself and the LinkedPortal is the other portal that the objects are coming out of.
Here’s the full code of the translation for anyone interested, though I’m pretty sure the issue is up there:
Quaternion portalRotation = Quaternion.FromToRotation(LinkedPortal.transform.parent.rotation.eulerAngles, transform.parent.rotation.eulerAngles); // Rotation between portals
Quaternion normalRotation = Quaternion.Euler(0,180,0); // Default Rotation of 180 degrees
//Update Position
Vector3 pos = transform.position - player.transform.position;
pos = portalRotation * pos;
pos = normalRotation * pos;
pos = Vector3.Reflect(pos, (transform.up)); // Reflection to put clone on ground
pos += LinkedPortal.transform.position;
duplicate.transform.position = pos; //Assign Position
duplicate.transform.localEulerAngles = rot; //Assign Rotation
Debug.Log ("Quaternion:" + portalRotation);
Debug.Log ("result:" + portalRotation * new Vector3 (0,0,1));