Straight bullets

I’m attempting to make a 3D side-scrolling platformer. Players will be allowed to have a blaster. I used Roblox Forum’s to create a raycasting blaster, but because of the camera, the gun is constantly hitting the invisible walls. I want the bullets to go straight, like in the Roblox game Glass. Any support?

also here’s the script

local tool = script.Parent
local player = game:GetService("Players").LocalPlayer
local debounce = false

tool.Equipped:Connect(function(mouse)
    mouse.Button1Down:Connect(function()
        if debounce == false then
            debounce = true
        local ray = Ray.new(tool.NeonPart.CFrame.p, (mouse.Hit.p - tool.NeonPart.CFrame.p).unit * 300)
        local part, position = workspace:FindPartOnRay(ray, player.Character, false, true)
 
        local beam = Instance.new("Part", workspace)
        beam.BrickColor = BrickColor.new("Bright red")
        beam.FormFactor = "Custom"
        beam.Material = "Neon"
        beam.Transparency = 0.25
        beam.Anchored = true
        beam.Locked = true
        beam.CanCollide = false
 
        local distance = (tool.NeonPart.CFrame.p - position).magnitude
        beam.Size = Vector3.new(0.3, 0.3, distance)
        beam.CFrame = CFrame.new(tool.NeonPart.CFrame.p, position) * CFrame.new(0, 0, -distance / 2)
 
        game:GetService("Debris"):AddItem(beam, .1)
 
        if part then
            local humanoid = part.Parent:FindFirstChild("Humanoid")
 
            if not humanoid then
                humanoid = part.Parent.Parent:FindFirstChild("Humanoid")
            end
 
            if humanoid then
                humanoid:TakeDamage(30)
            end
            wait(.5)
            debounce = false
            end
        end
    end)
end)
2 Likes

If I’m correct about what you are trying to create and shooting bullets in front of the player, like the photo provided (random one of google) then you could use LookVector: CFrame

1 Like

https://gyazo.com/8e024b0301533d64b9b55d7f5c42e7cb

I believe you can do this by using CFrames & a little camera manipulation.

Also in the script you may want to turn Anchored off for the bullet to go in the direction of the player’s mouse rather than the where the mouse is click towards.