Projectile is being shot in the wrong direction while walking backwards

I’m trying to make a tp aiming system using cframed projectiles and raycasting but when my character walks backwards the arrow doesn’t travel to direction where the humanoidRootPart is facing even thought its lookvector never changes

Here a video showing the hrp while moving:

Code:

function ShootArrow(character: Model)
	local hrp: BasePart = character.HumanoidRootPart
	
	local arrow: Model = replicatedStorage.Arrow:clone()
	arrow.Parent = workspace
	
	local t: number = 0.017
	local x0: Vector3 = firePoint.WorldPosition
	local v0: Vector3 = hrp.CFrame.LookVector * 300 + hrp.CFrame.UpVector * 10
	
	local params: RaycastParams = RaycastParams.new()
	params.FilterType = Enum.RaycastFilterType.Blacklist
	params.FilterDescendantsInstances = {character, arrow}
	
	arrow:SetPrimaryPartCFrame(firePoint.WorldCFrame)
	
	local connection: RBXScriptConnection

	connection = runService.Heartbeat:Connect(function(dt)
		local position: Vector3 = position(x0, v0, t)
		local velocity: Vector3 = velocity(v0, t)
		
		local result: RaycastResult = workspace:Raycast(arrow.PrimaryPart.Position, velocity * dt, params)
		
		if result then
			if result.Instance.Parent:FindFirstChild("Humanoid") then
				result.Instance.Parent:FindFirstChild("Humanoid").Health -= 10
			end
			debris:AddItem(arrow, 3)
			connection:Disconnect()
		else
			arrow:SetPrimaryPartCFrame(CFrame.lookAt(position, position + velocity))
			t += dt
		end
	end)
end

Could the arrow be colliding with the player perhaps?

I might suggest using collision groups maybe

1 Like

I agree with him, it seems like the issue has to do with collisions.
I think it would be best if you made a collision group for the player and projectiles fired from said player.
The idea is that the collision group of the projectiles can interact with the rest of the world EXCEPT the collision group the player is in. (And vice-versa)

function position(x0: Vector3, v0: Vector3, t: number): Vector3
	return x0 + (t * v0)
end

function velocity(v0: Vector3, t: number): Vector3
	return v0
end

 workspace.ChildAdded:Connect(function(child)
	if workspace:FindFirstChild(child.Name) then
		ShootArrow(child)
	end
end)

It shouldn’t, the parts of the model have CanCollide to false (may have to double check this, will do tommorow)

All parts to false and it doesn’t work so I don’t think that’s the problem

OK so the problem was the FirePoint attachment, its orientation made the arrow face down the first frame and mess up the direction(?)
Anyways it’s working fine now