How can I make this effect?

Hi! I’m working on a game that involves a building system. It’s kinda boring rn. I saw this devlog of a tycoon and he made this breaking effect. It’s where when an item is destroyed pieces fly out and at the end they get smaller and fade. I have looked it up and can’t find anything on it. I have linked the timestamp to the video here.

How could achieve this?

I assume this just positions a bunch of unanchored parts at the same spot with cancollide off, then throw them into a random direction and using .Touched you can tween the size.

Idk about the performance though, if you want better performance you would need to do complicated math.

Looks like they might be breaking up parts from the model into smaller parts. I’m sure you could find a library for this in Community Resources, so I’ll skip over that aspect here. Once the “fragment” parts are created, iterate over them and for each part:

  1. Create a tween using TweenService to shrink the part.
  2. Unanchor and apply an impulse using ApplyImpulse and ApplyAngularImpulse.
  3. Add the part to Debris (or queue the deletion of the part by some other means)

Code for creating each tween might look like:

local shrinkInfo = TweenInfo.new(2, Enum.EasingStyle.Linear, Enum.EasingDireciton.Out, 0, false, 0.5) --You can modify these values to your liking
function createShrinkingPart(part: BasePart): Tween
   return TweenService:Create(part, shrinkInfo, { Size = Vector3.zero })
   --Note: This function only creates the Tween. In order to play the tween you will need to call the method `:Play()` on it
end

Code for applying an impulse might look like:

function applyImpulse(part: BasePart)
   part.Anchored = false
   local mass = part:GetMass()
   --Note: These variables will likely need tweaking to achieve the desired effect
   local randomVerticalImpulse = Vector3.new(0, 4*math.random(), 0) * mass
   local randomRotationImpulse = Vector3.new(math.random(), math.random(), math.random()) * mass
   part:ApplyImpulse(randomVerticalImpulse)
   part:ApplyAngularImpulse(randomRotationImpulse)
end

You may also want to consider using a CollisionGroup for the fragment parts. The collision group could prevent fragment parts from colliding with each other and characters, however maintain collision with the rest of the world (likely the “Default” CollisionGroup) so fragment parts still collide with the ground, floor, walls, other non-deleted placed models, etc.

4 Likes

later on in the video you can see that the effect is made more simply (though I would love to plug my voxel destruction library here)

The creator just unanchors/unwelds every part and gives them random impulses. At the same time, they have their size tweened smaller (as you explained). It’s a neat effect!

1 Like

I’ll check out your library and try and get the same effect. Thanks

1 Like

Currently the library is set up to just delete the voxels, I will go ahead and make a destruction callback so you can create this effect more easily.

EDIT: It is done, you can do it like this:

local ShatterEvent = game:GetService("ReplicatedStorage"):WaitForChild("QueueShatter")

local ball = workspace.Ball2



local function DeleteCallback(part : BasePart)

	part.Anchored = false

	-- do random impulses

	game.Debris:AddItem(part, 1)
end


ShatterEvent:Fire(ball, DeleteCallback)

The drawback is that you’d need to create a temporary part encompassing the whole model just to get the intersection. In the future I will add a method to completely destroy something with just a call.

Thought this would be be a fun challenge so I tried it.

First, I got the bounding box of the model and calculate both corners. Then I used the solution from this post to position each debris part within the model. From there, I launch each part up and in a random direction using the assembly properties before tweening it’s size and transparency out.

In this effect, the positioning of the parts and their movement can be approached differently. In the video, it looked like the parts were more organized, next to each other almost forming a cube with the cubes, then each one was fired outwards. Both of which I could not figure out how to do.

Here’s the game file if anyone is curious:
EffectTest.rbxl (59.6 KB)

3 Likes