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

How can I make a cube move by rolling face to face?

Hi, I'd like to have a cube that rolls face-to-face, but I'm having trouble getting the script to work correctly. I'd like a result similar to this. For now I'm trying on only the X-Axis until I can get a good result. Here's what I have so far:

local CUBE = script.Parent
local CUBESize = CUBE.Size.X

local CUBEMoveInc = 10
local CUBEWaitSpeed = 0.25

local CUBECurrentlyMoving = false

local CUBEFaceBottom = CUBE["AttachmentY-"]
local CUBEFaceTop = CUBE["AttachmentY+"]
local CUBEFaceFront = CUBE["AttachmentZ+"]
local CUBEFaceBack = CUBE["AttachmentZ-"]
local CUBEFaceRight = CUBE["AttachmentX-"]
local CUBEFaceLeft = CUBE["AttachmentX+"]

function CUBEstep(dir)	
	if dir == "x" and not CUBECurrentlyMoving then
		CUBECurrentlyMoving = true
		for i = 1, CUBEMoveInc do
			CUBE.CFrame = CFrame.new(CUBE.Position.X + (CUBESize / CUBEMoveInc), CUBE.Position.Y, CUBE.Position.Z, CUBE.Orientation.X, CUBE.Orientation.Y, CUBE.Orientation.Z + (45 / CUBEMoveInc), 1)
			wait(CUBEWaitSpeed)
		end
	elseif dir == "y" and not CUBECurrentlyMoving then
		CUBECurrentlyMoving = true
		for i = 1, CUBEMoveInc do
			CUBE.CFrame = CFrame.new(CUBE.Position.X, CUBE.Position.Y + (CUBESize / CUBEMoveInc), CUBE.Position.Z)
			wait(CUBEWaitSpeed)
		end
	elseif dir == "z" and not CUBECurrentlyMoving then
		CUBECurrentlyMoving = true
		for i = 1, CUBEMoveInc do
			CUBE.CFrame = CFrame.new(CUBE.Position.X, CUBE.Position.Y, CUBE.Position.Z + (CUBESize / CUBEMoveInc))
			wait(CUBEWaitSpeed)
		end
	elseif dir == "-x" and not CUBECurrentlyMoving then
		CUBECurrentlyMoving = true
		for i = 1, CUBEMoveInc do
			CUBE.CFrame = CFrame.new(CUBE.Position.X - (CUBESize / CUBEMoveInc), CUBE.Position.Y, CUBE.Position.Z)
			wait(CUBEWaitSpeed)
		end
	elseif dir == "-z" and not CUBECurrentlyMoving then
		CUBECurrentlyMoving = true
		for i = 1, CUBEMoveInc do
			CUBE.CFrame = CFrame.new(CUBE.Position.X, CUBE.Position.Y, CUBE.Position.Z - (CUBESize / CUBEMoveInc))
			wait(CUBEWaitSpeed)
		end
	elseif dir == "-y" and not CUBECurrentlyMoving then
		CUBECurrentlyMoving = true
		for i = 1, CUBEMoveInc do
			CUBE.CFrame = CFrame.new(CUBE.Position.X, CUBE.Position.Y - (CUBESize / CUBEMoveInc), CUBE.Position.Z)
			wait(CUBEWaitSpeed)
		end
	end
	
	CUBECurrentlyMoving = false
end

CUBEstep("x")

1 answer

✓ Accepted answer

If you want something like what's shown in the Fortnite clip, and you want it to be smoothly animated and realistic looking for everyone, you should not do it by setting part CFrames, you should be using a VectorForce constraint to literally push the cube over, or a Torque object to give it an impulse to rotate. Or a hinge, or alignOrientation, or basically anything but CFrames. You should never animate physically-interacting things on the server by setting part CFrames, that's how you get terrible laggy looking animations and players flung out of the world from suddenly finding themselves overlapping a collidable part.

2 comments

0

Here goes a hero ^

0

Thank you!

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