Help with launching item on drop

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.

1 Like

newItem.PrimaryPart.AssemblyLinearVelocity = Vector3.new()?
if you really cant find a answer i suggest just using velocity until you find a answer
also you if changing newItem.PrimaryPart.AssemblyLinearVelocity = Vector3.new() doesnt work but changing the velocity works you shouldent mark me as the answer because you should never permanently use deprecated methods

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.