Skip to content

CVR.Portal

Portal API

Provides wrapped access to active portals.

For portal-related events, see Available Events - Portal Events.

Instance Members

Instance Properties

Signature Description
Player Spawner Returns the player who created this portal.\nThis can be null if the portal is created by the Game Server or World.
GameObject RootObject The root GameObject of the portal
Transform RootTransform The root Transform of the portal

Instance Methods

Signature Description
Vector3 GetPosition() Returns the world position of portal
Quaternion GetRotation() Returns the world rotation of portal
void SetPosition(Vector3 pos) Sets the world position of portal
void SetRotation(Quaternion rot) Sets the world rotation of portal

Example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/// Simple script that keeps portals within 2 meters of the player that spawned them
public partial class PortalFollower : WasmBehaviour
{
    private readonly List<Portal> _spawnedPortals = new();

    private void OnPortalCreated(Portal portal) => _spawnedPortals.Add(portal);
    private void OnPortalDestroyed(Portal portal) => _spawnedPortals.Remove(portal);

    private void Update()
    {
        foreach (Portal portal in _spawnedPortals)
        {
            Player dropper = portal?.Spawner;
            if (dropper == null) continue;

            Vector3 portalPos = portal.GetPosition();
            Vector3 dropperPos = dropper.GameObject.transform.position;
            if (Vector3.Distance(portalPos, dropperPos) > 2f)
            {
                Vector3 direction = (portalPos - dropperPos).normalized;
                portal.SetPosition(dropperPos + direction * 2f);
            }
        }
    }
}