Explosion Effect

Hello. I was wondering how I could achieve an effect like this, https://gyazo.com/19db126f936d2761904cdc995e55c0a1, where there are blocks or rather parts exploding outwards when the fire projectile hits something. I could try tweening each part by itself, but it wouldn’t look natural nor would it look good. I could also unanchor a bunch of parts, but they would just fall straight down. Any suggestions on how I could do this would be highly appreciated! :slight_smile:

8 Likes

Try thinking about the steps that have been taken.
For example an object is thrown and then an explosion occurs and then the debris are scattered around the area.
First step is throw something.
Script that first.

3 Likes

Sorry but this is not quite the answer I was looking for. I was looking for a solid answer that mentions what I would need to use, such as Vector, CFrame and BodyForce.

I’ve been brainstorming some ideas using the lookVector, rightVector and upVector and come to a conclusion.

If you find the Cross value between some of them you can get the diagonal directions, which then you can use BodyPosition to tell it to go in that direction and have Physics applied to the debris.

Now you’ll need to get the CFrame of where the projectile hit the object, if this is raycasting then you can wrap the returned Position (FindPartOnRay) in a CFrame.new constructor with the lookAt as the direction of the ray:

--hitPos is the returned Position, rayDirection is the direction of the ray
local cframe = CFrame.new(hitPos, rayDirection)

Next, it’s time to find the diagonal directions:

--// Given horizontals
local Right = cframe.RightVector
local Left = -Right
local Forward = cframe.LookVector
local Back = -Forward
--// Given verticals
local Up = cframe.UpVector
local Down = -Up

--// Main diagonals
local FrontRight = Front:Cross(Right)
local FrontLeft = Front:Cross(Left)
local BackRight = Back:Cross(Right)
local BackLeft = Back:Cross(Left)

local FrontUpRight = Up:Cross(FrontRight)
local FrontUpLeft = Up:Cross(FrontLeft)
local BackUpRight = Up:Cross(BackRight)
local BackUpLeft = Up:Cross(BackLeft)

local FrontDownRight = Down:Cross(FrontRight)
local FrontDownLeft = Down:Cross(FrontLeft)
local BackDownRight = Down:Cross(BackRight)
local BackDownLeft = Down:Cross(BackLeft)

Finally, once you’ve got all these directions you can apply different debris to go in these directions.
Now keep in mind not to set too much P or else it’ll just fly up or down in that direction
For example:

local BP = Instance.new("BodyPosition")
BP.Position = FrontUpRight * 30
BP.P = 20
BP.Parent = DebrisPart --The part of your debris

I’m not too good with Cross products, so if anyone spots a problem then do reply.

3 Likes

I am not sure what that is to do with this post.

When the projectile hits the wall, find the directionals of where it hit and then send debris in those directions.
This is mainly what my post is showing; how to get those directions.
Here’s a diagram if you don’t get what I mean:

1 Like

Ok, got it. And. Thank you. So back to Corealle for a response.

1 Like

How to get hitPos and rayDirection?

rayDirection is the Vector3 direction for the ray to fire which you pass to WorldRoot:Raycast() or Ray.new().

hitPos is the Vector3 position where the ray hit that is the Position property of the RaycastResult returned from WorldRoot:Raycast() or the second item of the tuple returned from Workspace:FindPartOnRay().


Of course, you can use whatever CFrame you may want to (incl. a BasePart’s CFrame). This is just constructing a CFrame from a raycast.

I tested your code, but the Front variable isn’t exist

Is meant to be:
local Front = cframe.LookVector

Note: The piece of code is an example of how you could get multiple directional vectors from a part.

Tested and this is the result.

External Media
while script.Parent.BodyVelocity.Velocity == Vector3.new(0,2,0) do wait() end
wait(.1)
local start = script.Parent.Position
local stop
local action
action = script.Parent.Touched:Connect(function(hit)
	action:Disconnect()
	stop = script.Parent.Position
	local Direction = start-stop
	local cframe = CFrame.new(stop, Direction)
	local Right = cframe.RightVector
	local Left = -Right
	local Front = cframe.LookVector
	local Back = -Front
	local Up = cframe.UpVector
	local Down = -Up

	local FrontRight = Front:Cross(Right)
	local FrontLeft = Front:Cross(Left)
	local BackRight = Back:Cross(Right)
	local BackLeft = Back:Cross(Left)

	local FrontUpRight = Up:Cross(FrontRight)
	local FrontUpLeft = Up:Cross(FrontLeft)
	local BackUpRight = Up:Cross(BackRight)
	local BackUpLeft = Up:Cross(BackLeft)

	local FrontDownRight = Down:Cross(FrontRight)
	local FrontDownLeft = Down:Cross(FrontLeft)
	local BackDownRight = Down:Cross(BackRight)
	local BackDownLeft = Down:Cross(BackLeft)
	local bomb = Instance.new("Explosion",script.Parent)
	bomb.Position = script.Parent.Position
	bomb.DestroyJointRadiusPercent = 0
	bomb.BlastRadius = 10
	--bomb.
	bomb.BlastPressure = 100000
	bomb.ExplosionType = Enum.ExplosionType.NoCraters
	local Clone1 = hit:Clone()
	Clone1.Anchored= false
	Clone1.Size = Vector3.new(3,3,3)
	Clone1.Parent = workspace
	Clone1.Position = script.Parent.Position
	local BP = Instance.new("BodyPosition")
	BP.Position = FrontUpRight * 30
	BP.P = 20
	BP.Parent = Clone1 --The part of your debris
	game.Debris:AddItem(Clone1,3)
	game.Debris:AddItem(script.Parent,5)
end)
1 Like