I’m trying to make a top-down shooter and working on the framework for the weapon system, but I ran into a problem I forgot how to fix and can’t find on DevForum. I want to make a raycast go to the mouse, but I want it to go past it, and I can’t figure out how to do that from a top-down perspective. I’m also unable to use the character’s root part because I want it to be accurate.
What I want:
What I get:
Code:
userinputservice.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
local function raycast(origin,point)
local distance = (origin - point).Magnitude
local p = Instance.new("Part")
p.Anchored = true
p.CanCollide = false
p.Size = Vector3.new(0.1, 0.1, distance)
p.CFrame = CFrame.lookAt(origin, point)*CFrame.new(0, 0, -distance/2)
p.Parent = game.Workspace
end
local root = character.HumanoidRootPart
local origin = root.Position + root.CFrame.LookVector * 2
local point = Vector3.new(mouse.Hit.X, origin.Y, mouse.Hit.Z)
local raycastResult = workspace:Raycast(origin, point)
if raycastResult then
raycast(origin,raycastResult.Position)
else
raycast(origin,point)
end
end
end)
I’m lost and don’t know how to achieve this and any help would be appreciated, thanks.

