Can someone explain the math in this impact crater please?

  1. What do you want to achieve? Keep it simple and clear!
    I want to write my own, so i wanted to see some examples of impact craters i liked to study them.

  2. What is the issue? Include screenshots / videos if possible!
    I found one but i don’t understand really the math in there and now i’m stuck on making my own.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Searching for some explanations around devforum / youtube, but haven’t found any

for i = 1, (20 * Mod)/10 do

	local segments = math.random(8,12)

	for i2 = 0, segments - 1 do

		local potCf = CF * CFrame.Angles(0,math.rad(360/segments) * i2, 0) * CFrame.new(0,0, (i * -(20 * Mod)/3) - 5)

		local result = workspace:Raycast(potCf.Position + Vector3.new(0,3,0), Vector3.new(0,-10,0), params)

		if result then

			local GroundBreak = repStorage.GroundBreak
			if GroundBreak then
				local hb = GroundBreak:Clone()
				
				hb.Color = result.Instance.Color
				hb.Material = result.Material
				hb.Size = Vector3.new(math.random(8,14) * 10 * Mod/segments,math.random(5,6),math.random(5,10))

				hb.CFrame = potCf
				hb.Position = result.Position - Vector3.new(0,5,0)
				hb.CFrame *= CFrame.Angles(math.rad(math.random(10,45)),0,0)

				TweenModule.obj(hb, "Back", "Out", .3, {Position = hb.Position + Vector3.new(0,3,0)})

				task.delay(.3,function()

					TweenModule.obj(hb, "Back", "In", .3, {Position = hb.Position - Vector3.new(0,6 * Mod,0)})

				end)

				game.Debris:AddItem(hb, 1.5)
			end
			
		end
	end
	wait()
end

Example of what the script does:

is this the whole script, because either I’m blind or there’s no Mod variable

Mod is just number 1, idk why it was added but heres an example of what it does:

First it repeats 20 times (times the Mod variable), for each ring of the crater, like these:
image
…and each time it repeats it comes up with a random number of segments to create for the crater ring, like these:
image
Then it gets the CFrame of where the segment is supposed to be placed later (with the Y Rotation being 360 / segments * i2, i2 being the index of the segment creation loop), and then it casts a ray to get the Material and Color of the floor below.
Then if the ray hits something, the script gets a Part (i’m assuming) from ReplicatedStorage, and checks if the Part exists.
Then the script clones the part and sets the Material and Color which was obtained from the raycast result.
Then the script sets a random Size for the part, positions the part at potCF, which was where the ray was cast, then it lowers the Y Position by 5 studs, and randomly rotates the part on the X Axis, then it uses a TweenModule to tween the part up 3 studs on the Y axis.
Then the script waits 0.3 seconds, using task.delay and then tweens the part downwards 6 studs times the Mod variable (which i’m assuming stands for modifier)
Then the script uses Debris (game:GetService("Debris")) to delete the part after 1.5 seconds using :AddItem()

i might’ve lazied out at a few parts, so if you have any questions, feel free to ask.

1 Like

The first part, it repeats 20 times, is that for each ring, and then each time it repeats it gets a segment OF that ring, and then rotates it accordingly? is i2 responsible for creating the segment?

  • when it repeats 20 times, yes it’s repeating for each ring
  • i2 is the current number of segments created, or the progress of the loop (so if i2 is 5, that means that the loop has currently repeated 5 times. this article explains it more thoroughly)
  • the script gets a Part object from ReplicatedStorage, and then the script clones it and places colors n stuff. it doesn’t get a segment of the ring, because the segments aren’t there yet.
1 Like

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