So my problem is that im trying to create a rock effect that anime games have where once i kick you into the air, once u land i create a raycast that detects 10 studs below you and then creates the rock effect. The problem is that the raycast goes through parts into multiple layers → basically my floor has multiple layers becuase tahts how the builder made it and i dont’ want to mess with that, but becuase of that, the raycast detects the bottommost layer and not the visible one so the parts spawn on the lower layer which is obviously a problem b/c thast not visible for the players.
Heres the code :
local module = {}
local TS = game:GetService("TweenService")
function module.Rocks(part2Tp: part)
print("running")
local RayParams = RaycastParams.new()
RayParams.FilterDescendantsInstances = {}
RayParams.CollisionGroup = "Raycast"
RayParams.FilterType = Enum.RaycastFilterType.Exclude
local angle = 0
for i=1,25 do
local size = math.random(1.5,2)
local Rock = Instance.new("Part")
Rock.Transparency = 0
Rock.Parent = game.Workspace.DebrisFolder
Rock.Size = Vector3.new(size,size,size)
Rock.CFrame = part2Tp.CFrame * CFrame.fromEulerAnglesXYZ(0, math.rad(angle), 0) * CFrame.new(-10, -10, 0)
Rock.Parent = game.Workspace.DebrisFolder
Rock.Anchored = true
Rock.CanCollide = false
Rock.Transparency = 1
Rock.Material = Enum.Material.Basalt
Rock.Color = Color3.fromRGB(0,0,0)
game.Debris:AddItem(Rock,8)
local RayCast = workspace:Raycast(Rock.CFrame.p, Rock.CFrame.UpVector * -5, RayParams) -- raycast created from workspace
-- use the rocks cframe with its upward direction * -5 ( below the rock) to check whats under it
if RayCast then
--repeat wait() until ( part2Tp.Position - RayCast.Position).Magnitude < 10
print("sum here")
Rock.Transparency = 0
Rock.Position = RayCast.Position
Rock.Material = RayCast.Material
Rock.Color = RayCast.Instance.Color
else
print("nun here")
Rock.Transparency = 1
end
Rock.Orientation = Vector3.new(math.random(-180,180), math.random(-180,180), math.random(-180,180)) -- random direction the part faces
local TweenOutInfo = TweenInfo.new(1,Enum.EasingStyle.Linear,Enum.EasingDirection.In,0,false,0)
local TweenOutGoals = {Position = Rock.Position + Vector3.new(0,-5,0), Transparency = 1}
local TweenOut = TS:Create(Rock,TweenOutInfo,TweenOutGoals)
task.delay(5,function()
task.wait(5)
TweenOut:Play()
end)
angle += 14.4
end
end
return module