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

How to stop rotation bounciness/glitchyness?

CODE IS AT END, BUT READ DESCRIPTION FIRST, PLEASE.

Hello! I recently got inspired by the game "Cube Simulator," and I wanted to see if I could try to recreate a randomly rotating cube. Of course, in the game, it's not randomly rotated, but I digress, I ran into a problem while testing. After a long stretch of coding, the cube rotated as intended. But every so often, instead of rotating smoothly, the cube bounces around and then goes back to the normal, smooth rotation again.

In other words, the rotation property for the cube (normal part object, by the way) goes smoothly across 1 or 2 axes, just as I want to. However, occasionally all three properties go crazy. The properties' movement don't even match anything I put in. It's just glitchy bouncing.

___________________________________________________________________________

Here's some info that's not mentioned in the code:

Yes, I'm using the Rotation property with Vector instead of EulerAnglesXYZ with CFrame, which I will change later, but that shouldn't make a difference in terms of the glitchy movement because the cube is floating above the baseplate, and no physical objects ever touch it.

The cube's size is (10,10,10).

The cube is Anchored, CanCollide, Archivable, Symmetric, and (obviously) block-shaped.

No other properties that might affect its movement have been changed, like velocity, friction, etc.

___________________________________________________________________________

Don't fear the length of the code, it's just a slightly altered for loop pasted 18 times. Here:

print("Pasta's CubeRotator Loaded")
_G.Kelly = true

local cube = script.Parent

repeat
	print("Repeat loop started.")
	local direction = math.random(1,18)
	local speed = math.random(1,3)
	
	if direction == 1 then
		print(direction..": "..cube.Rotation.X,","..cube.Rotation.Y,",",cube.Rotation.Z)
		for i = 1,math.random(30,120) do
			local w = wait(0.03)
			cube.Rotation = Vector3.new(cube.Rotation.X+1+(w/0.03-1),cube.Rotation.Y,cube.Rotation.Z)
		end
	elseif direction == 2 then
		print(direction..": "..cube.Rotation.X,","..cube.Rotation.Y,",",cube.Rotation.Z)
		for i = 1,math.random(30,120) do
			local w = wait(0.03)
			cube.Rotation = Vector3.new(cube.Rotation.X,cube.Rotation.Y+1+(w/0.03-1),cube.Rotation.Z)
		end
	elseif direction == 3 then
		print(direction..": "..cube.Rotation.X,","..cube.Rotation.Y,",",cube.Rotation.Z)
		for i = 1,math.random(30,120) do
			local w = wait(0.03)
			cube.Rotation = Vector3.new(cube.Rotation.X,cube.Rotation.Y,cube.Rotation.Z+1+(w/0.03-1))
		end
	elseif direction == 4 then
		print(direction..": "..cube.Rotation.X,","..cube.Rotation.Y,",",cube.Rotation.Z)
		for i = 1,math.random(30,120) do
			local w = wait(0.03)
			cube.Rotation = Vector3.new(cube.Rotation.X-1+(w/0.03-1),cube.Rotation.Y,cube.Rotation.Z)
		end
	elseif direction == 5 then
		print(direction..": "..cube.Rotation.X,","..cube.Rotation.Y,",",cube.Rotation.Z)
		for i = 1,math.random(30,120) do
			local w = wait(0.03)
			cube.Rotation = Vector3.new(cube.Rotation.X,cube.Rotation.Y-1+(w/0.03-1),cube.Rotation.Z)
		end
	elseif direction == 6 then
		print(direction..": "..cube.Rotation.X,","..cube.Rotation.Y,",",cube.Rotation.Z)
		for i = 1,math.random(30,120) do
			local w = wait(0.03)
			cube.Rotation = Vector3.new(cube.Rotation.X,cube.Rotation.Y,cube.Rotation.Z-1+(w/0.03-1))
		end
	elseif direction == 7 then
		print(direction..": "..cube.Rotation.X,","..cube.Rotation.Y,",",cube.Rotation.Z)
		for i = 1,math.random(30,120) do
			local w = wait(0.03)
			cube.Rotation = Vector3.new(cube.Rotation.X+1+(w/0.03-1),cube.Rotation.Y+1+(w/0.03-1),cube.Rotation.Z)
		end
	elseif direction == 8 then
		print(direction..": "..cube.Rotation.X,","..cube.Rotation.Y,",",cube.Rotation.Z)
		for i = 1,math.random(30,120) do
			local w = wait(0.03)
			cube.Rotation = Vector3.new(cube.Rotation.X,cube.Rotation.Y+1+(w/0.03-1),cube.Rotation.Z+1+(w/0.03-1))
		end
	elseif direction == 9 then
		print(direction..": "..cube.Rotation.X,","..cube.Rotation.Y,",",cube.Rotation.Z)
		for i = 1,math.random(30,120) do
			local w = wait(0.03)
			cube.Rotation = Vector3.new(cube.Rotation.X+1,cube.Rotation.Y,cube.Rotation.Z+1+(w/0.03-1))
		end		
	elseif direction == 10 then
		print(direction..": "..cube.Rotation.X,","..cube.Rotation.Y,",",cube.Rotation.Z)
		for i = 1,math.random(30,120) do
			local w = wait(0.03)
			cube.Rotation = Vector3.new(cube.Rotation.X-1+(w/0.03-1),cube.Rotation.Y-1+(w/0.03-1),cube.Rotation.Z)
		end		
	elseif direction == 11 then
		print(direction..": "..cube.Rotation.X,","..cube.Rotation.Y,",",cube.Rotation.Z)
		for i = 1,math.random(30,120) do
			local w = wait(0.03)
			cube.Rotation = Vector3.new(cube.Rotation.X,cube.Rotation.Y-1+(w/0.03-1),cube.Rotation.Z-1+(w/0.03-1))
		end		
	elseif direction == 12 then
		print(direction..": "..cube.Rotation.X,","..cube.Rotation.Y,",",cube.Rotation.Z)
		for i = 1,math.random(30,120) do
			local w = wait(0.03)
			cube.Rotation = Vector3.new(cube.Rotation.X-1+(w/0.03-1),cube.Rotation.Y,cube.Rotation.Z-1+(w/0.03-1))
		end		
	elseif direction == 13 then
		print(direction..": "..cube.Rotation.X,","..cube.Rotation.Y,",",cube.Rotation.Z)
		for i = 1,math.random(30,120) do
			local w = wait(0.03)
			cube.Rotation = Vector3.new(cube.Rotation.X-1+(w/0.03-1),cube.Rotation.Y+1+(w/0.03-1),cube.Rotation.Z)
		end	
	elseif direction == 14 then
		print(direction..": "..cube.Rotation.X,","..cube.Rotation.Y,",",cube.Rotation.Z)
		for i = 1,math.random(30,120) do
			local w = wait(0.03)
			cube.Rotation = Vector3.new(cube.Rotation.X,cube.Rotation.Y-1+(w/0.03-1),cube.Rotation.Z+1+(w/0.03-1))
		end	
	elseif direction == 15 then
		print(direction..": "..cube.Rotation.X,","..cube.Rotation.Y,",",cube.Rotation.Z)
		for i = 1,math.random(30,120) do
			local w = wait(0.03)
			cube.Rotation = Vector3.new(cube.Rotation.X-1+(w/0.03-1),cube.Rotation.Y,cube.Rotation.Z+1+(w/0.03-1))
		end	
	elseif direction == 16 then
		print(direction..": "..cube.Rotation.X,","..cube.Rotation.Y,",",cube.Rotation.Z)
		for i = 1,math.random(30,120) do
			local w = wait(0.03)
			cube.Rotation = Vector3.new(cube.Rotation.X+1+(w/0.03-1),cube.Rotation.Y,cube.Rotation.Z-1+(w/0.03-1))
		end
	elseif cube.Rotation == 17 then
		print(direction..": "..cube.Rotation.X,","..cube.Rotation.Y,",",cube.Rotation.Z)
		for i = 1,math.random(30,120) do
			local w = wait(0.03)
			cube.Rotation = Vector3.new(cube.Rotation.X,cube.Rotation.Y+1+(w/0.03-1),cube.Rotation.Z-1+(w/0.03-1))
		end
	elseif cube.Rotation == 18 then
		print(direction..": "..cube.Rotation.X,","..cube.Rotation.Y,",",cube.Rotation.Z)
		for i = 1,math.random(30,120) do
			local w = wait(0.03)
			cube.Rotation = Vector3.new(cube.Rotation.X+1+(w/0.03-1),cube.Rotation.Y-1+(w/0.03-1),cube.Rotation.Z)
		end
	end
	
	print("For loop exited.")
until _G.Kelly == false

print("Repeat loop exited.")

___________________________________________________________________________

In case you're wondering:

The reason I declared the variable w between each for loop is to compensate for CPU usage (which is 0.001%, but other things can eat it up too.) Added it in case of lag.

_G.Kelly is just a force-stop mechanism I can use while testing, just ignore it.

___________________________________________________________________________

Anyway, thanks for reading; all replies are appreciated, -Pasta

1 answer

Alright, see if using CFrame fixes your problem. The vanilla Rotation property can be buggy.

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