The origin of the ray is changing position

  1. What do you want to achieve?
    I want to origin not to change position
    2.What is the issue?
    When I look up origin position breaks.
  2. What solutions have you tried so far?
    I tried looking on internet for the solution

Video:


Code:

local function Shoot()
	local Origin = workspace.CurrentCamera:FindFirstChild("Viewmodel" .. GunName):FindFirstChild(GunName).Barrelt.Position
	local Direction = workspace.CurrentCamera:FindFirstChild("Viewmodel" .. GunName):FindFirstChild(GunName).Barrelt.CFrame.LookVector
	local DirectionCF = CFrame.new(Vector3.new(), Direction)
	local SpreadDir = CFrame.fromOrientation(0,0,math.random(0, math.pi * 2))
	local SpreadAngle = CFrame.fromOrientation(math.rad(math.random(GunModule.MIN_SPREAD, GunModule.MAX_SPREAD)),0,0)
	local FinalDirection = (DirectionCF * SpreadDir * SpreadAngle).LookVector
	local caster = FastCastModule.new()
	caster.Fire(caster,Origin, FinalDirection, 250, behavior)
	
	caster.RayHit:Connect(function(cast, hit, part, material, distance)
		if hit then
			--print(hit.Instance)
			script.Parent.Fire:FireServer(hit.Instance, GunModule.Damage)
		end
	end)
end
1 Like

Here is all you should likely need to do for spread to work correctly:

I hope this helped you. It helped me.

1 Like

If you temporarily disabled Spread, is the trajectory still off? Try putting your Barrelt a bit higher up on the gun.

Okay I will try do everything you both said.
Sorry for not responding

I am sorry but none of yours methods didn’t work

I am very sorry, I wrote “Trajectory” but my current problem is the origin that changes the position.