UnityRef is currently in early development. Some features may be incomplete and/or not functioning.

UNITYREF

Your Pit Stop For Solving ANYTHING in Unity

physics

Incorrect Teleport Rotation Delta

Under Audit

quaternion

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.

Issue

 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.

Experimental Fixes
  • Ensure both Portal GameObjects have their local forward axes pointing in the intended direction of teleportation flow.* Calculate the rotational difference between the LinkedPortal.transform.rotation and the current Portal.transform.rotation, then apply this delta to the teleported object’s rotation.* Consider using Transform.TransformDirection or Transform.InverseTransformDirection to convert the teleported object’s velocity or local direction into the LinkedPortal’s local space before applying it.

Editor's Note:

The above fixes have not been verified by our audit team yet. They are provided exclusively for your own technical research. We recommend creating a backup of your project before proceeding with any attempts. Utilize at your own discretion!

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.