hey there, I was messing around in my game to make a cool “ground slice” kind of thing and made it so that even if you jump the slice would always be anchored to the ground, however I encountered a really weird problem where sometimes if I jump or be completely still, this happens
as you can see, this is not a really good raycast and all the blocks are placed awkwardly all over the place
but other times, it would be like this
which is a good raycast
this is the original code:
local rapture_thing = script.Parent
local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Exclude
raycastParams.FilterDescendantsInstances = {script.Parent}
raycastParams.IgnoreWater = true
local function match_material(
part_:BasePart
)
local raycastResult = workspace:Raycast(
part_.Position,
(part_.CFrame.UpVector) * -1000,
raycastParams
)
if raycastResult and raycastResult.Instance then
local new_part = Instance.new("Part", workspace)
local new_highlight = Instance.new("Highlight")
part_.Color = raycastResult.Instance.Color
part_.Material = raycastResult.Instance.Material
part_.Position = raycastResult.Position
print("hit and positioned")
task.spawn(function()
task.wait(3)
new_part.Size = Vector3.new(2,2,2)
new_part.Position = raycastResult.Position
new_part.Anchored = true
new_highlight.Parent = new_part
end)
else
print("nothing hit and returned")
end
end
task.wait()
for _, part in rapture_thing:GetChildren() do
if not part:IsA("Part") then continue end
if part.Name == ("Slice" or "Position") then continue end
match_material(part)
end
I’m not really sure where I went wrong with this, because it should turn out fine, unless I’m using the raycast properties wrong?
if you have any solutions, please help me out! thanks