How can I make bullets pass through portals?

Hello! I was having fun merging the Roblox FPS Template with a portal system made by the community

I was wondering how to make the projectiles passing to the portals.

In theory, a projectile passes through the portal through a three-step process:

Collision: The ray (Raycast) is fired from the blaster and stops as soon as it touches the surface of Portal A. The system calculates the distance the projectile would have traveled. I think there is already a raycast system on the blaster modules.

Mathematical Translation: The impact point is converted into “relative coordinates” with respect to Portal A. These coordinates are then applied to Portal B, rotating them 180° to ensure the projectile exits in the correct direction.

Recursion: A second ray is instantly fired, starting
from Portal B and continuing for the remaining distance.

Visually, the script draws two separate segments (Blaster → A and B → Target), giving the illusion of a single projectile traversing space.

This is the place if you want to make some edits and tries:
Portal System x Template DevForum.rbxl (177.5 KB)

Said that, I have no clue of where to start, and I don’t have any mathematics knowledge to do that.
Please help :sob:

2 Likes

I don’t think you should hard code a 180 degree flip if you want it to be modular so you can then put portals anywhere at any angle.

Your best bet is to have portals the same size and always have a specific face (such as ‘Front’) always be the actual portal face.

This means that when a player shoots a specific co-ord on the portal you can accurately replicate that on the second or even mirror it if desired.

From here yeah you just store the angle of the shot so that when it ‘comes out’ the other portal (respawned) it is still continuing to travel the same angle as if it went through

4 Likes

Yes, for now, that’s exactly how it is. The portals are the same shape and size and use the Front Face. I was talking about turning it 180 degrees to get the mirrored effect. However, the problem remains that I don’t know how to apply it to the code. :confused:

1 Like

I assume it’d be as simple as a local offset from the portal that was first hit, and then applying that local offset to the other B portal. Say you shoot 2 studs off from the center of the A portal, still hitting the portal, and it’d “come out of” or teleport 2 studs off from the center of the B portal.

I think

offset = (portalA.position - raycastHitPoint.Position) 

newRay = portalB.position + offset 

My overview solution doesn’t account for shooting at an angle from the portal. Just it shooting out from the normal. So, angle calculation somewhere.


There’s a lot of scripts though for raycasting / shooting. I think what you’d want to change would be under ReplicatedStorage → Utility. Maybe castRays or drawRayResults.

Add a tag on the part/mesh for Portal, check for the tag on the raycast, and if it’s that tag for what was hit → fire another raycast at that new position with whatever offset and/or angle.


I think this would be similar to the billiards game @sleitnick made. Firing multiple Raycasts with angle information.

3 Likes
local offset = portal1.CFrame:PointToObjectSpace(rayHit.Position)

local direction = (portal1.CFrame.Rotation + rayHit.Position):PointToObjectSpace(gun.Position)

local origin = portal2.CFrame:PointToWorldSpace(offset)

workspace:RayCast(origin, direction, ...)
1 Like

Thank you @Reditect and @xxxwectorxxx for this! The main problem, integrating it on the existing blaster system

2 Likes

Yeah modifying and reviewing code is probably alot harder than writing it from scratch. Just try your best to locate what to change within the code.

1 Like