Projectiles not following player position

making a gun system, but i have this issue where the weapons doesn’t follow me when im moving, im currently using parabola for projectile system for it

local function fireBullet(origin, direction)
local parabola = Parabola.new()
parabola:setPhysicsLaunch(origin, direction * config.BULLET_SPEED, nil, 35 * -config.GRAVITY_FACTOR)

local bulletTemplate = BulletAssets:FindFirstChild("BulletTracer")
if not bulletTemplate then
	warn("BulletTracer not found in ReplicatedStorage > GunAssets > BulletEffects")
	return
end

local bullet = bulletTemplate:Clone()
bullet.Anchored = true
bullet.CanCollide = false
bullet.Position = origin
bullet.Parent = workspace

-- Orient bullet to face the direction it's traveling
local lookDirection = direction
bullet.CFrame = CFrame.lookAt(origin, origin + lookDirection)

local travelTime, maxTime = 0, config.MAX_DISTANCE / config.BULLET_SPEED
local lastPosition = origin

local conn
conn = RunService.Heartbeat:Connect(function(dt)
	travelTime = travelTime + dt
	if travelTime > maxTime then 
		conn:Disconnect()
		bullet:Destroy()
		return 
	end

	local t0, t1 = (travelTime - dt) * config.BULLET_SPEED, travelTime * config.BULLET_SPEED
	parabola:setDomain(t0, t1)

	-- Check for hit first
	local hitPart, hitPoint = parabola:findPart({player.Character})
	if hitPart then
		-- Position bullet at hit point
		bullet.Position = hitPoint

		-- Change color to indicate hit
		bullet.BrickColor = BrickColor.Red()

		-- Handle hit logic
		local targetModel = hitPart:FindFirstAncestorOfClass("Model")
		local humanoid = targetModel and targetModel:FindFirstChildOfClass("Humanoid")

		if humanoid then
			local isHeadshot = hitPart.Name == "Head"
			remotes:WaitForChild("Hit"):FireServer(humanoid, hitPoint, hitPart.Name, isHeadshot)
		end

		conn:Disconnect()
		-- Keep bullet visible briefly before destroying
		task.delay(0.1, function() 
			if bullet and bullet.Parent then
				bullet:Destroy() 
			end
		end)
		return
	end

	-- Update bullet position and orientation
	local currentPos = parabola:samplePoint(1)
	local travelDirection = (currentPos - lastPosition).Unit

	-- Only update if we have a valid direction
	if travelDirection.Magnitude > 0 then
		bullet.CFrame = CFrame.lookAt(currentPos, currentPos + travelDirection)
	else
		bullet.Position = currentPos
	end

	-- Store current position for next frame
	lastPosition = currentPos
end)

end

what do you mean the weapon doesnt follow you

and can you show where origin is being defined and changed

1 Like

Try subtracting the player’s velocity from the origin

it was the muzzlehole attachment where the projectile comes from

local function fireSingleBullet()
if state.currentAmmo <= 0 then
if config.AUTO_RELOAD and state.totalAmmo > 0 then task.spawn(reload) end
return false
end

if state.isInspecting then toggleInspect() end

local character = player.Character
if not character then return false end

local handle = tool:FindFirstChild("Handle")
local muzzleHole = handle and handle:FindFirstChild("MuzzleHole")
local origin = muzzleHole and muzzleHole.WorldPosition or character.Head.Position
local baseDirection = (mouse.Hit.Position - origin).Unit

-- ENABLE MUZZLE PARTICLES AND LIGHTS
if muzzleHole then
	local particleEmitters = {}
	local lights = {}

	-- Find all ParticleEmitters and Lights in MuzzleHole
	local function findEffects(container)
		for _, child in pairs(container:GetChildren()) do
			if child:IsA("ParticleEmitter") then
				table.insert(particleEmitters, child)
			elseif child:IsA("Light") or child:IsA("PointLight") or child:IsA("SpotLight") or child:IsA("SurfaceLight") then
				table.insert(lights, child)
			elseif child:IsA("Attachment") then
				-- Recursively check attachments
				findEffects(child)
			end
		end
	end

	findEffects(muzzleHole)

	-- Enable all found particle emitters
	for _, emitter in pairs(particleEmitters) do
		emitter.Enabled = true
	end

	-- Enable all found lights
	for _, light in pairs(lights) do
		light.Enabled = true
	end

	-- Disable effects after a short duration
	task.delay(0.1, function() -- Adjust timing as needed (0.1 seconds default)
		for _, emitter in pairs(particleEmitters) do
			if emitter and emitter.Parent then
				emitter.Enabled = false
			end
		end
		for _, light in pairs(lights) do
			if light and light.Parent then
				light.Enabled = false
			end
		end
	end)
end

-- Fire bullets
for i = 1, config.NUM_SHOTS do
	fireBullet(origin, applySpreadToDirection(baseDirection))
end

applyRecoil()
state.currentAmmo = state.currentAmmo - 1
updateAmmoDisplay()
remotes.Fired:FireServer()

if #shootAnimationTracks > 0 then
	shootAnimationTracks[randomGenerator:NextInteger(1, #shootAnimationTracks)]:Play()
end
return true

end