I’m having issues where raycast is dropping off the mouse for no apparent reason? The ray should go from the tip of my gun, and hit right where my mouse is. But for some reason there’s a slight drop off, for no apparent reason? Am I doing the math wrong?
local Mouse = UserInputService:GetMouseLocation() or self.Player:GetMouse()
local UnitRay = workspace.CurrentCamera:ScreenPointToRay(Mouse.X, Mouse.Y)
local FirePoint = self.FirePoint.WorldPosition
local WallRaycast = workspace:Raycast(
UnitRay.Origin,
FirePoint - UnitRay.Origin,
CastParams
)
if WallRaycast then -- Infront of wall
FirePoint = UnitRay.Origin
end
local Direction
local HitRaycast = workspace:Raycast(
UnitRay.Origin,
UnitRay.Direction * 1000,
CastParams
)
if HitRaycast then
Direction = (HitRaycast.Position - FirePoint).Unit
end