So I’m trying to launch the tool when the player drops it but my code doesn’t work with mass correctly.
Some objects launch further than others and I need help fixing that. I want the objects to launch the same.
Code:
local function getTotalObjectMass(object)
local mass = 0
for i, v in ipairs(object:GetDescendants()) do
if v:IsA("BasePart") then
mass += v.AssemblyMass
end
end
return mass
end
local function dropItem(item)
local head = character:FindFirstChild("Head")
if item and head then
local newItem = item:Clone()
newItem:PivotTo(head.CFrame + head.CFrame.LookVector * 3)
newItem.Parent = PickupableItems
local mass = getTotalObjectMass(newItem)
local launchPower = 50
local launchDirection = head.CFrame.LookVector
local launchVelocity = launchDirection * mass * launchPower
if newItem.PrimaryPart then
newItem.PrimaryPart.AssemblyLinearVelocity = Vector3.new()
newItem.PrimaryPart:ApplyImpulse(launchVelocity)
end
end
end
All my objects are not massless.