Hello! I have a script that makes bullets and make them ricochet but I also have other shooting weapons that use bodyVelocity to shoot. I want to make the bullet also use bodyVelocity how to I do it? Heres my code:
local hrp = plr.Character:FindFirstChild("HumanoidRootPart")
local function Shoot()
local rng = Random.new()
local laser = Instance.new("Part")
laser.Name = "Laser"
laser.TopSurface = Enum.SurfaceType.Smooth
laser.BottomSurface = Enum.SurfaceType.Smooth
laser.Color = Color3.new(rng:NextNumber(), rng:NextNumber(), rng:NextNumber())
laser.Anchored = true
laser.CanCollide = false
laser.Locked = true
laser.CFrame = hrp.CFrame
laser.Parent = workspace
local maxDistance = 200
local curDistance = 0
local stepDistance = 4
local stepWait = 0
local currentPos = hrp.Position
local currentNormal = hrp.CFrame.LookVector
local function Step(overrideDistance)
-- Cast ray:
local params = RaycastParams.new()
local direction = currentNormal * (overrideDistance or stepDistance)
params.FilterType = Enum.RaycastFilterType.Blacklist
params.FilterDescendantsInstances = {hrp}
local result = workspace:Raycast(currentPos, direction)
local pos
if result then
pos = result.Position
else
pos = currentPos + direction
end
-- Update laser position:
laser.Size = Vector3.new(0.4, 0.4, (pos - currentPos).Magnitude)
laser.CFrame = CFrame.new(currentPos:Lerp(pos, 0.5), pos)
local oldPos = currentPos
currentPos = pos
if result then
-- r = d - 2(d DOT n)n
-- Reflect:
local norm = result.Normal
local reflect = (currentNormal - (2 * currentNormal:Dot(norm) * norm))
currentNormal = reflect
Step(stepDistance - (pos - oldPos).Magnitude)
return
end
curDistance = (curDistance + (pos - oldPos).Magnitude)
-- Apply fade effect to laser as it approaches max distance from < 75 studs:
if curDistance > (maxDistance - 75) then
local d = (curDistance - (maxDistance - 75)) / 75
laser.Transparency = d
end
-- Recurse if max distance not reached:
if curDistance < maxDistance then
wait(stepWait)
Step()
end
end
Step()
-- Done! Destroy laser:
laser:Destroy()
end
Shoot() -- Fire shot!
Thank you for reading this please help me out thanks!