Incorrect Teleport Rotation Delta
Under Audit
Unity 2021.3.x - Unity 6.1.x
Published 13 days ago
When implementing a portal system in your project, objects may only teleport correctly when portals are precisely aligned. Calculating the rotational delta for the teleported object when portals are not facing each other proves challenging, leading to incorrect orientation after teleportation.
When implementing a Portal system where objects are teleported between two Portal instances, a rotational discrepancy can occur. The current implementation correctly handles position-based teleportation but struggles with applying the correct rotation when the linked Portal instances are not perfectly aligned (e.g., having a 180° difference on the Y-axis). This limitation means that the teleported object's movement is not altered only when it passes through straight-facing portals. The challenge lies in determining the appropriate delta rotation to apply to the teleported object to ensure its orientation relative to the destination Portal is consistent with its orientation relative to the source Portal, especially when using Quaternion for rotation calculations. Specifically, the line handling other.transform.rotation needs to incorporate this delta for accurate results.
- Ensure both
PortalGameObjectshave their local forward axes pointing in the intended direction of teleportation flow.* Calculate the rotational difference between theLinkedPortal.transform.rotationand the currentPortal.transform.rotation, then apply this delta to the teleported object’s rotation.* Consider usingTransform.TransformDirectionorTransform.InverseTransformDirectionto convert the teleported object’s velocity or local direction into theLinkedPortal’s local space before applying it.
Editor's Note:
Related Posts Haven't quite found a solution to your problem? We think these posts might help you.
Content inspired by a Unity discussion post.