Ive created a standard Raycast gun system which forms the rays on the client and does damage on the server, however, and issue arrises when the player is moving in a linear fashion or the mouse remains in the same position, the raycasts are casted at a very odd angle, not at all equal to the look vector, despite being directly attributed to it. below is the client sided script (only the main function) + video (THIS ISSUE DOES NOT EXIST WHEN THE PLAYER IS STATIONARY)
local function shoot()
if db == false and canShoot == true and CurrentAmmo > 0 then
CurrentAmmo -= 1
db = true
t.Click:FireServer(configs.Type)
local shootOrigin = player.Character.HumanoidRootPart.CFrame.Position
local direction = (player.Character.HumanoidRootPart.CFrame.LookVector * configs.Range)
local size1 = Vector3.new(0.5,1,0.5)
local params = RaycastParams.new()
params.FilterDescendantsInstances = {script.Parent,script.Parent.Parent}
params.FilterType = Enum.RaycastFilterType.Blacklist
local raycast = workspace:Raycast(shootOrigin,direction,params)
local intersection = raycast and raycast.Position or shootOrigin + direction
local distance = (shootOrigin - intersection).Magnitude
local bullet_clone = Instance.new("Part")
bullet_clone.Anchored = true
bullet_clone.CanQuery = false
bullet_clone.CanCollide = false
bullet_clone.Size = Vector3.new(0.1, 0.1, distance)
bullet_clone.CFrame = CFrame.new(shootOrigin, intersection)*CFrame.new(0, 0, -distance/2)
bullet_clone.Parent = game.Workspace
if raycast then
script.Parent.EffectHitEVent:FireServer(raycast.Position)
if raycast.Instance.Name == "Crate" then
EventsFolder.CratePunch:FireServer(raycast.Instance,configs.ObsticalDamage)
else
if raycast.Instance.Parent:FindFirstChild("Humanoid") then
if raycast.Instance.Name == "Head" then
ShootEvent:FireServer(raycast.Instance.Parent.Humanoid,raycast.Instance,true)
elseif raycast.Instance.Name ~= "Head" then
ShootEvent:FireServer(raycast.Instance.Parent.Humanoid,raycast.Instance,false)
end
end
end
end
ShootEvent:FireServer()
--
wait(configs.Cooldown)
db = false
end
end