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.
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
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.
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.
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.
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, ...)