#can some1 help with my fps game
1 messages · Page 1 of 1 (latest)
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)
hmmmm
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
where am i puttin this: workspace:Raycast(origin, direction, raycastParams)
where you're doing body velocity shit
?
here
oh
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................
what abt the max range variable? where do i define it?
** You are now Level 6! **
ohhhhhh
im dumb af