I’m having issues where shooting through a portal isn’t resulting your shot actually being correct, and closer you get, the more innacurate it gets. If your FirePoint (the tip of the gun) is clipping into a wall/portal, then I shoot from the camera, and it works perfectly, however I obviously need the bullet to come from the gun in most cases.
local MousePos = UserInputService:GetMouseLocation() or Mouse
if self.Mag > 0 then -- Can fire
local UnitRay = Camera:ViewportPointToRay(
MousePos.X,
MousePos.Y
)
local FirePoint = UnitRay.Origin
if self.WeaponFolder:FindFirstChild("Projectile") then
FirePoint = self.FirePoint.WorldPosition
local WallRaycast = workspace:Raycast(
UnitRay.Origin,
FirePoint - UnitRay.Origin,
CastParams
)
if WallRaycast then -- Infront of wall
FirePoint = UnitRay.Origin
end
end
local Direction
local HitRaycast = workspace:Raycast(
UnitRay.Origin,
UnitRay.Direction * 1000,
CastParams
)
if HitRaycast then
Direction = (HitRaycast.Position - FirePoint).Unit
end
if not Direction then
Direction = Camera.CFrame.LookVector * 1000
end
end