How do I make a block that always aligns itself to the block directly under the BottomSurface? I am attempting to make a block that hovers over the ground and will also cling to a roof if the block if flipped upside down.
Currently, I have a block that floats above the floor, but when touching something else, it will lose balance and won't regain the balance. (Note: Maybe an algorithm +bodygyro?)
My current code that allows the block to float.
local x = script.Parent
local bp = Instance.new("BodyPosition",x)
bp.maxForce = Vector3.new(0,math.huge,0)
local bg = Instance.new("BodyGyro")
game:GetService("RunService").Stepped:connect(
function()
local ray = Ray.new(x.Position,(x.CFrame*CFrame.new(0,-4,0).p-x.Position))
local hit,pos = game.Workspace:FindPartOnRay(ray,x)
local offset = (x.CFrame*CFrame.new(0,-3,0).p-x.Position)
local startpos = x.Position
if hit then
bp.maxForce = Vector3.new(0,math.huge,0)
bp.position = pos+Vector3.new(0,offset.y*-1,0)
else
bp.maxForce = Vector3.new(0,0,0)
bp.position = Vector3.new(0,0,0)
end
wait()
end)
Thanks :)

2 comments
What do you mean by "Losing Balance" ? Do you mean like the block is unrestrained and starts to roll indefinitely?
Correct, the block begins to "roll indefinitely"