#can some1 help with my fps game

1 messages · Page 1 of 1 (latest)

dusty matrix
#

i need help getting raycasting working on my shooting and thats it tbh

#

rn i just have a body vel which is depriciated and i wanna change to a newer system

#
    if player.Character then
        for i, v in pairs(player.Character.UpperTorso:GetChildren()) do
            if v.Name == "FireSound" then
                v:Destroy()
            end
        end
        
        local fireSound = Instance.new("Sound")
        fireSound.Parent = player.Character.UpperTorso
        fireSound.Name = "FireSound"
        fireSound.Volume = Volume
        fireSound.SoundId = SoundId
    end
end)

game.ReplicatedStorage.Events.Shoot.OnServerEvent:Connect(function(player, MuzzlePos, MousePos)
    if player.Character then
        local sound = player.Character.UpperTorso:FindFirstChild("FireSound")
        
        if sound then
            sound:Play()
        end
        

        local bullet = Instance.new("Part")
        bullet.Name = "Bullet"
        bullet.Parent = game.Workspace
        bullet.CanCollide = false
        bullet.Anchored = false
        bullet.Size = Vector3.new(.1, .1, .25)
        bullet.CFrame = CFrame.new(MuzzlePos, MousePos)
        bullet.Material = Enum.Material.Neon
        bullet.BrickColor = BrickColor.new("Yellow flip/flop")
        
        bullet:SetNetworkOwner(player)
        
        local bodyVelo = Instance.new("BodyVelocity")
        bodyVelo.Parent = bullet
        bodyVelo.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
        bodyVelo.Velocity = bullet.CFrame.lookVector * 100
        
        bullet.Touched:Connect(function(hit)
            bullet:Destroy()
            
            if hit.Parent ~= player.Character then
                if hit then
                    if hit.Parent:FindFirstChild("Humanoid") then
                        hit.Parent:FindFirstChild("Humanoid"):TakeDamage(15)
                    end
                end
            end
        end)
    end
end)
fossil fern
#

you can replace the phstics bullet with instant raycasting

using
workspace:Raycast(origin, direction, raycastParams)

and to calcluate direactions use
(MousePos - MuzzlePos).Unit * maxRange

#

and you need to setup the raycastparams properly , by creating raycastparams.new() and set a filtertype

dusty matrix
#

where am i puttin this: workspace:Raycast(origin, direction, raycastParams)

trim ice
dusty matrix
trim ice
dusty matrix
#

oh

trim ice
#

replace this with raycasting

#
local raycast = workspace:Raycast(origin, direction, raycastParams)

if not raycast then return end --guard break(or check i forgot) to check if you hit smth

etc................
dusty matrix
finite valleyBOT
#

studio** You are now Level 6! **studio

trim ice
#

in direction

#

maxRange is a number

dusty matrix
#

ohhhhhh

trim ice
#

local maxRange = 5

#

idk if its in studs or nah

#

ask him

dusty matrix
#

im dumb af