Ok , did this do you know how to calculate the time to reach for a bullet with bodyforce? (i’ll provide its bodyforce code below)
local module = {}
local ABS, HUGE, FLOOR, CEIL = math.abs, math.huge, math.floor, math.ceil
local RAD, SIN, COS, TAN = math.rad, math.sin, math.cos, math.tan
local VEC2, V3 = Vector2.new, Vector3.new
local CF, CFANG = CFrame.new, CFrame.Angles
local INSERT = table.insert
local Walking = false
local instance = Instance.new
local CFn = CFrame.new
local CFa = CFrame.Angles
local asin = math.asin
local abs = math.abs
local min = math.min
local max = math.max
local random = math.random
local RS = game:GetService("RunService")
local BDrop = 0.1
local BSpeed = 800
function Lerp(n,g,t)
return n+(g-n)*t
end
function RAND(Min, Max, Accuracy)
local Inverse = 1 / (Accuracy or 1)
return (math.random(Min * Inverse, Max * Inverse) / Inverse)
end
local TS = game:GetService("TweenService")
function module.CastRay(Bala,POS,char)
task.spawn(function()
local Hit2, Pos2, Norm2, Mat2
local Hit, Pos, Norm, Mat
local L_257_ = POS;
local L_258_ = Bala.Position;
local TotalDistTraveled = 0
local recast
local Ray_Ignore = {char}
while true do
RS.Heartbeat:wait()
L_258_ = Bala.Position;
TotalDistTraveled = TotalDistTraveled + (L_258_ - L_257_).magnitude
Hit2, Pos2, Norm2, Mat2 = workspace:FindPartOnRayWithIgnoreList(Ray.new(L_257_, (L_258_ - L_257_)*20), Ray_Ignore, false, true);
Hit, Pos, Norm, Mat = workspace:FindPartOnRayWithIgnoreList(Ray.new(L_257_, (L_258_ - L_257_)), Ray_Ignore, false, true);
Bala.CFrame=CFrame.new(Bala.Position,Bala.Position+Bala.Velocity)*CFrame.Angles(math.pi/2,math.pi*BDrop,0)
if Hit2 then
while not recast do
if Hit2 and (Hit2 and Hit2.Transparency >= 1 or Hit2.CanCollide == false and Hit2.Transparency == 1 or Hit2.Name == "Ignorable" or Hit2.Name == "Glass" or Hit2.Parent.Name == "Top" or Hit2.Parent.Name == "Helmet" or Hit2.Parent.Name == "Up" or Hit2.Parent.Name == "Down" or Hit2.Parent.Name == "Face" or Hit2.Parent.Name == "Olho" or Hit2.Parent.Name == "Headset" or Hit2.Parent.Name == "Numero" or Hit2.Parent.Name == "Vest" or Hit2.Parent.Name == "Chest" or Hit2.Parent.Name == "Waist" or Hit2.Parent.Name == "Back" or Hit2.Parent.Name == "Belt" or Hit2.Parent.Name == "Leg1" or Hit2.Parent.Name == "Leg2" or Hit2.Parent.Name == "Arm1" or Hit2.Parent.Name == "Arm2") and Hit2.Name ~= 'Right Arm' and Hit2.Name ~= 'Left Arm' and Hit2.Name ~= 'Right Leg' and Hit2.Name ~= 'Left Leg' and Hit2.Name ~= 'Armor' and Hit2.Name ~= 'EShield' then
table.insert(Ray_Ignore, Hit2)
recast = true
end
if recast then
Hit2, Pos2, Norm2, Mat2 = workspace:FindPartOnRayWithIgnoreList(Ray.new(L_257_, (L_258_ - L_257_)*20), Ray_Ignore, false, true);
Hit, Pos, Norm, Mat = workspace:FindPartOnRayWithIgnoreList(Ray.new(L_257_, (L_258_ - L_257_)), Ray_Ignore, false, true);
recast = false
else
break
end
end
end
local NewPart = Instance.new("Part")
if Hit and not recast then
Bala:Destroy()
if Hit.Parent:FindFirstChild("Humanoid") then
Hit.Parent:FindFirstChild("Humanoid"):TakeDamage(5)
end
if Hit.Parent.Parent:FindFirstChild("Humanoid") then
Hit.Parent.Parent:FindFirstChild("Humanoid"):TakeDamage(5)
end
if Hit.Parent.Parent.Parent ~= workspace and Hit.Parent.Parent.Parent ~= nil then
if Hit.Parent.Parent.Parent:FindFirstChild("Humanoid") then
Hit.Parent.Parent.Parent:FindFirstChild("Humanoid"):TakeDamage(5)
end
end
if Hit.Parent:FindFirstChild("Enemy") then
Hit.Parent:FindFirstChild("Enemy"):TakeDamage(5)
end
if Hit.Parent.Parent:FindFirstChild("Enemy") then
Hit.Parent.Parent:FindFirstChild("Enemy"):TakeDamage(5)
end
if Hit.Parent.Parent.Parent ~= workspace and Hit.Parent.Parent.Parent ~= nil then
if Hit.Parent.Parent.Parent:FindFirstChild("Enemy") then
Hit.Parent.Parent.Parent:FindFirstChild("Enemy"):TakeDamage(5)
end
end
break
end
L_257_ = L_258_;
end
end)
end
function module.CreateBullet(BSpread,CF,POS,bul)
local Bullet = Instance.new("Part")
Bullet.Name = "C_Bullet"
Bullet.CanCollide = false
Bullet.Transparency = 1
Bullet.FormFactor = "Custom"
Bullet.Size = Vector3.new(1,1,1)
local BulletMass = Bullet:GetMass()
local Force = Vector3.new(0,BulletMass * (game.Workspace.Gravity) - (BDrop) * (game.Workspace.Gravity), 0)
local Origin = POS
local Direction = CF.lookVector + (CF.upVector * (((BDrop*1/2.8)/BSpeed))/2)
local BulletCF = CF
local balaspread = CFrame.Angles(
RAD(RAND(-BSpread - ((0/1)*0), BSpread + ((0/1)*0)) / 20),
RAD(RAND(-BSpread - ((0/1)*0), BSpread + ((0/1)*0)) / 20),
RAD(RAND(-BSpread - ((0/1)*0), BSpread + ((0/1)*0)) / 20)
)
Direction = balaspread * Direction
Bullet.CFrame = BulletCF + Direction
local NewClone = bul:Clone()
NewClone.CFrame = Bullet.CFrame
NewClone.Parent = Bullet
local NewWeld = Instance.new("WeldConstraint")
NewWeld.Part0 = Bullet
NewWeld.Part1 = NewClone
NewWeld.Parent = Bullet
Bullet.Parent = script.Parent.Parent
Bullet.Velocity = Direction * BSpeed
local BF = Instance.new("BodyForce")
BF.force = Force
BF.Parent = Bullet
--CreateShell()
game.Debris:AddItem(Bullet, 5)
return Bullet
end
return module
Bspread is bullet spread, CF is the shooter part’s CFRAME, POS is the shooter parts Position,char is just the turret model.
Maybe we can calculate it with BSpeed?