Custom Explosion Force On Click

So I made two scripts that help make an explosion effect on models when clicked on.
However the explosion doesn’t feel very satisfying, I’d like a spherical explosion effect but my script just unanchored and :ApplyImpule() into a random direction.

Local Script:

local mouse = game.Players.LocalPlayer:GetMouse()
local destruction = game.ReplicatedStorage:WaitForChild("Destruction")

mouse.Button1Down:Connect(function()
	local target = mouse.Target
	
	if target and target:FindFirstAncestorOfClass("Model") then
		for _, v in pairs(target.Parent:GetDescendants()) do
			destruction:FireServer(v)
			print(v.Name)
		end
	else
		if target.Name ~= "Baseplate" then
			target.Anchored = false
			destruction:FireServer(target)
			print(target.Name)
		end
		
	end	
end)

Server Script:

local destruction = game.ReplicatedStorage:WaitForChild("Destruction")

destruction.OnServerEvent:Connect(function(player, part)
	local character = player.Character or player.CharacterAdded:Wait()
	local torso:Part = character:WaitForChild("Torso")
	if part and part:IsA("Part") then
		part.Anchored = false
		
		local orientation, size = part.Parent:GetBoundingBox()
		print(orientation.p)
		
		for _, v:Part in pairs(workspace:GetPartBoundsInRadius(orientation.p, 2)) do
			v:ApplyImpulse((v.Position - orientation.p)*50)
		end
	end
	if part and part:IsA("ManualWeld") then
		print(part.Name)
		part:Destroy()
	end
end)

Demonstration:

If I understand correctly. By “spherical explosion effect” you mean you want to shoot the parts away from the center of the crate.

If that’s the case then this should work:

local direction = (v.Position - ThePartInTheCenterOfTheCrate.Position).Unit
v:ApplyImpulse(direction * 50)

Sorry I don’t know how you named the part in the center of the crate, so just replace the ThePartInTheCenterOfTheCrate with the name of the part that’s in the center.

1 Like

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