Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I make a block that aligns itself to the floor? (Still unanswered... 1m+)

How do I make a block that always aligns itself to the block directly under the BottomSurface of the block? 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?)

What I mean by lose balance is that the block will roll out of control.

Examples of alignment:

Image, red is aligned part

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 :)

1 answer

ok, if you don't know how to align a brick to the floor... ugh. OK, ROBLOX has just made a new feature called Transform, or something like that. Use that to help you, and also, you will see a grey ring around it which will help you. Hope that helps.

1 comment

1

no. no.

This discussion is preserved as it was. New answers, comments, and votes are closed.