Portals: Transformation of ported Objects


I’m currently working at a portalsystem.
Transforming the velocity and the position of ported objects works great, but I just can’t get the rotation to work.

My current system is build up of two planes portalA and portalB. If they have the same rotation their normals are looking in the opposite direction (mirrored meshs).

The code

obj.transform.rotation = portalA.transform.rotation * (obj.transform.rotation * Quaternion.Inverse(portalB.transform.rotation));

seems to work only with some portal-rotations correctly. Other arrangements of the quaternions seem to work neither. So what I need are a few univesal lines of code to correctly transform the rotation of an object from portalA to portalB like in the picture below (The object in the picture isn’t rotated correctly, but it visualizes the case).


Maybe anyone of you could help me?

If you need some more information just write it. :wink:

Okay, I found it out myself (trial and error :D).

For those who are interested:

Porting the position:

obj.transform.position = portalB.transform.TransformPoint(portalA.transform.InverseTransformPoint(obj.transform.position));

Porting the rotation (you maybe have to rotate the object additionally 180° around portalB.transform.up):

obj.transform.rotation = portalB.transform.rotation * Quaternion.Inverse(portalA.transform.rotation) * obj.transform.rotation;

Porting the velocity:

Rigidbody objRigid = obj.GetComponent<Rigidbody>();
objRigid.velocity = portalB.transform.TransformDirection(portalA.transform.InverseTransformDirection(objRigid.velocity));

I hope I could help some of you, because there wasn’t a clear answer anywhere. :slight_smile: