To get started, create two Portal3D instances and set their ExitPortal to each other.
This creates a linked portal pair that you can look through. Make your player to collide with TeleportCollisionMask and you will be able to walk back and forth through the portal.
To integrate portals into your game, you can make use of the SignalsOnTeleport and OnTeleportReceive during gameplay.
The next level is to make use of the portal’s callbacks, mainly OnTeleportCallback.
If you need to raycast through a portal checkout the ForwardRaycast and ForwardRaycastQuery methods.
For optimization, use the Activate and Deactivate methods to control which portals are consuming resources.
TIP: For easy defaults management of various portals, create a scene with Portal3D and the root and re-use that scene instead.
public class Portal3D : Node3D
| name | description |
|---|---|
| Portal3D() | The default constructor. |
| delegate OnTeleportEventHandler | Emitted when this portal teleports something. |
| delegate OnTeleportReceiveEventHandler | Emitted when this portal receives a teleport. |
| Activate() | Activates the portal and recreates internal viewports if needed. |
| Deactivate(…) | Disables all processing and hides the portal. Optionally destroys the viewports, freeing memory. |
| ForwardRaycast(…) | Helper method for checking for raycast collisions through portals. Implement a method that checks your RayCast3D collisions and if it hits a portals Area3D then forward the ray through the portal: |
| ForwardRaycastQuery(…) | When doing raycasts directly with PhysicsDirectSpaceState3D.IntersectRay(), implement a method that checks your collisions and if a portal is hit, pass the PhysicsRayQueryParameters3D to this method. |
| Callback OnTeleportCallback | A method for use in objects that teleport. |
| Callback DuplicateMeshesCallback | A method for use in objects that teleport with duplicate meshes turned on. |
| Callback TeleportRootMeta | By default, the object triggering the teleport gets teleported. You can override this with a metadata property that contains a NodePath. |
| PortalSize { get; set; } | Size of the portal rectangle, height and width. |
| ExitPortal { get; set; } | The exit of this portal. The portal camera renders what it sees through the exit portal and teleports take you there. |
| PlayerCamera | Set this to manually override the main camera of the scene. By default it’s inferred as the camera rendering the parent viewport of the portal. |
| PortalFrameWidth { get; set; } | The portal camera sets its Camera3D.Near as close to the portal as possible in an effort to clip objects close behind the portal. |
| ViewportSizeMode { get; set; } | Size mode to use for the portal viewport size. Only set this via the inspector. |
| enum PortalViewportSizeMode | Options for different sizes of the internal viewports. This helps to reduce memory usage by not rendering the portals at full resolution. Viewports are resized on window resize. |
| ViewDirection { get; set; } | The direction from which you expect the portal to be viewed. Restricting this restricts the way the portal mesh is shifted around when player looks at the portal from different sides. |
| enum PortalViewDirection | Options for the direction from which you expect the portal to be viewed. |
| PortalRenderLayer { get; set; } | The portal mesh setting for the visual instance layer(s) so that portal camera don’t see other portals. |
| IsTeleport { get; set; } | If true, the portal is also a teleport. |
| TeleportDirection { get; set; } | Portal will only teleport objects from the direction(s) set. |
| enum PortalTeleportDirection | Options for the direction an object has to enter the portal to be teleported. |
| RigidbodyBoost { get; set; } | When a RigidBody3D goes through the portal, give its new normalized velocity a little boost. Makes objects flying out of portals more fun. |
| TeleportTolerance { get; set; } | When teleporting, the portal checks if the teleported object is less than this near. |
| TeleportInteractions { get; set; } | See PortalTeleportInteractions for options and info. |
| enum PortalTeleportInteractions | Flags for events that happen when something is teleported. |
| TeleportCollisionMask { get; set; } | Any collision objects detected by this mask will be registered by the portal and teleported when they cross the boundary. |
| StartDeactivated { get; set; } | If the portal is not immediately visible on scene start, it can be started in disabled mode. It will not create the subviewports, saving memory. |
| ViewportSizeFractional | The fraction to use for fractionalization of the viewports. |
| ViewportSizeMaxWidthAbsolute | “this” wide for use in MaxWidthAbsolute setting of portal viewport size mode. |