Been struggling with this one for a while now, this crater spawns a few studs away from me;
So depending on where i am on my map, the crater get’s positioned differently:
local RootPosition = things.Origin.Position
local craterSize = 10
local radius = 5
local rnd = Random.new()
local numCircles = rnd:NextInteger(3, 5)
for h = 1, numCircles do
local numParts = rnd:NextInteger(10, 15)
for i = 1, numParts do
local rock = Instance.new("Part")
local rockSize = Vector3.new(rnd:NextNumber(1.5, 2.2), rnd:NextNumber(1, 2), rnd:NextNumber(1.4, 2))
rockSize *= h/numCircles
local orientation = Vector3.new(rnd:NextNumber(-60, 60), rnd:NextNumber(-60, 60), rnd:NextNumber(-60, 60))
local xOffset = rnd:NextNumber(-radius, radius)
local zOffset = rnd:NextNumber(-radius, radius)
local lookAt = Vector3.new(RootPosition.X + xOffset, RootPosition.Y, RootPosition.Z + zOffset)
local LookVector = CFrame.new(RootPosition, lookAt).LookVector
local position = RootPosition + (LookVector * radius * math.clamp(h/numCircles, 0.4, 1))
local NewCFrame = CFrame.new(position, RootPosition + LookVector + orientation)
local RayParams = RaycastParams.new()
RayParams.FilterDescendantsInstances = {workspace.Map}
RayParams.FilterType = Enum.RaycastFilterType.Include
local floorRay = workspace:Raycast(NewCFrame.Position + Vector3.new(0, 3, 0), position - Vector3.new(0, 100, 0), RayParams)
if floorRay and floorRay.Instance.Anchored then
local colour = floorRay.Instance.Color
local mat = floorRay.Instance.Material
rock.Size = Vector3.new(0, 0, 0)
rock.Position = floorRay.Position
rock.Orientation = orientation
rock.CanCollide = false
rock.Anchored = true
rock.TopSurface = Enum.SurfaceType.Smooth
rock.Color = colour or Color3.fromRGB(83, 86, 90)
rock.Material = mat or Enum.Material.Slate
rock.Parent = workspace.Effects
TweenModule.obj(rock, "Quad", "Out", .3, {Size = rockSize})
task.spawn(function()
task.wait(1)
local fallTween = TweenModule.obj(rock, "Quad", "Out", .3, {Size = Vector3.new(0,0,0)})
fallTween.Completed:Wait()
rock:Destroy()
end)
end
end
task.wait()
end