Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
PortalGun
A portal gun that actually works. Shoot a blue and an orange portal, walk through keeping your momentum, and haul loot between them. One per run, works in co-op. Still in testing.
| Date uploaded | 21 hours ago |
| Version | 1.0.2 |
| Download link | TheMorningStar-PortalGun-1.0.2.zip |
| Downloads | 381 |
| Dependency string | TheMorningStar-PortalGun-1.0.2 |
This mod requires the following mods to function
BepInEx-BepInExPack
BepInEx pack for Mono Unity games. Preconfigured and ready to use.
Preferred version: 5.4.2100README
Portal Gun
Adds the Aperture Science Handheld Portal Device to the list of shop items. Press E to toggle portal gun mode while holding the item, and then it controls like the portal gun controls in its games. Semibots, enemies, loot, and everything else should pass through fine.
Still in testing. Portals touch a lot of game systems, so expect some jank. Everyone in the lobby needs the mod installed. Portal placement is synced, and there is one gun per run.
What it does
- Shop item: appears in the shop rotation priced $15,000 to $20,000, one in the shop at a time, one gun per run.
- Controls: hold the gun and press E to enter portal mode. The gun is force-held in portal mode, so left-click fires instead of dropping it. LMB fires the blue portal, RMB the orange, MMB clears the pair.
- Portals: door-sized at 1.3m by 2.2m, fired at the flat surface under your crosshair up to 60m away. Re-firing a portal moves it. Once both exist they link, with a live view through the opening, and things pass through.
- What goes through: you, other players, held and thrown loot, and enemies. Momentum carries. Enemies also hear and see through a linked pair, so a lure played near one portal draws them to the other side.
- Performance: portals show a live view of the other side, which costs frames to render. The
PortalQualitysetting lowers the resolution of that view to save performance. Its default,Auto, does that on its own when your framerate drops.
Configuration
- PortalQuality, default
Auto:Autodrops the resolution under load,Highrenders it at full resolution,Balancedat half,Performanceat a third. - DevKeys, default
false: developer test keys, off for normal play.
For developers - detailed breakdown
Requires REPOLib for item registration and the networking below. The rendering math, relative-transform camera mirroring with an oblique near-clip projection, is ported from Sebastian Lague's MIT-licensed Portals project, and the portal screen shader is his Custom/Portal shader shipped as-is in the asset bundle.
Teleport core. Crossing detection is an analytic FixedUpdate check with no Unity trigger callbacks or collision-matrix involvement. The trigger volume extrudes 0.4m out from the portal face, 1.4m for items whose centers sit farther from walls. A body-center plane check alone can never fire on a wall-mounted portal, because the wall's own collider stops the player capsule about 0.3 to 0.4m short of a quad 0.05m off the surface. Exit placement is inset 0.8m from the destination wall, outside that portal's own trigger volume so arriving cannot re-trigger, with a minimum exit speed of 1 m/s and a 1s per-object cooldown against ping-pong. Velocity carries through the portal-pair rotation delta, and camera rotation applies through CameraAim.SetPlayerAim, since raw Transform writes lose to CameraAim's per-frame recompute. One measured value matters when forking this: REPO's player rigidbody falls at about 2.5x Physics.gravity, so vertical-launch math has to use the measured figure.
Rendering. The portal camera's far plane is computed per render, the player-to-portal distance plus the main camera's fog-tight view distance of about 23m, clamped to 30 to 150. PortalQuality maps to a render-texture downscale of 1 for High, 2 for Balanced, 3 for Performance, and Auto also skips portal-camera renders under sustained frame-time load.
Enemy awareness. Sound events near one portal are remapped through EnemyDirector.SetInvestigate to the paired opening, and throttled master-only EnemyVision.VisionTrigger relays let an enemy that sees one portal react to a player at the other. Enemies cannot path through. They cross only when their physics body crosses the plane.
Multiplayer. Portal fire and clear are REPOLib NetworkedEvents, "PortalGunFire" and "PortalGunClear", reliable and raised to others, and each client places the same quad locally. Item and player crossings resolve on the owner's side. RunManager.ChangeLevel runs only on the master, so per-level cleanup accounts for non-master clients separately.
Shop wiring. The item registers through REPOLib's bundle scan, then a fixup pass prices it at $15k to $20k over the bundle's placeholder, sets itemType to a shop-eligible tool type, sets itemVolume = medium so shop shelves place it at a medium slot, and sets maxAmountInShop = 1. A singleton guard keeps it one per run against a dupe glitch or another mod spawning a second.
A portal needs a flat area big enough for the quad. Too curved, too small, or too close to an edge and it fizzles instead of placing. Re-firing a portal moves it.