Custom AutoRotate normal to one side, janky to another

I’m making a custom autorotate script that uses BodyGyro to smoothly change the player’s root part orientation as humanoid.MoveDirection changes

But for some reason that i still don’t even know why, the smoothness disappears when the character is rotating mid-air to the right. It works as intended when moving to the left (???)

The localscript in question:

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local rootPart = character:WaitForChild("HumanoidRootPart")

local UIS = game:GetService("UserInputService")

local SMOOTH_FACTOR = 20

local bodyGyro = rootPart:FindFirstChild("HumanoidRotation") or Instance.new("BodyGyro")
bodyGyro.Name = "HumanoidRotation"
bodyGyro.Parent = rootPart

local d = 0
local p = 1000

bodyGyro.D = d
bodyGyro.P = p

bodyGyro.MaxTorque = Vector3.new(0, p, 0)

local shiftOrFirstPerson = false

UIS:GetPropertyChangedSignal("MouseBehavior"):Connect(function()
	if UIS.MouseBehavior == Enum.MouseBehavior.LockCenter then
		shiftOrFirstPerson = true
	else
		shiftOrFirstPerson = false
	end
end)

local function updateBodyGyro()
	local moveDirection
	local camera = workspace.CurrentCamera
	local cameraDirection = camera.CFrame.LookVector

	if not shiftOrFirstPerson then
		moveDirection = humanoid.MoveDirection
	else
		moveDirection = cameraDirection + (humanoid.MoveDirection / 4)
	end

	if moveDirection.Magnitude > 0 then
		local angle = math.deg(math.acos(math.abs(moveDirection.Unit:Dot(rootPart.CFrame.LookVector))))

		if moveDirection.Unit:Dot(rootPart.CFrame.LookVector) < 0 then
			angle = 180 - angle
		end

		local oppositeAngle = 180 - angle

		if oppositeAngle > 15 then
			local newDirection = moveDirection * SMOOTH_FACTOR
			local newRotation = Vector3.new(newDirection.X, newDirection.Y, newDirection.Z).Unit
			bodyGyro.CFrame = CFrame.new(rootPart.Position, rootPart.Position + newRotation)
		end
	end
end

game:GetService("RunService").Heartbeat:Connect(updateBodyGyro)

(This localscript is located inside StarterCharacter → StarterCharacterScripts → Other [a folder i’ve made for less important scripts])

OBS: Problem happens specifically here:

local newDirection = moveDirection * SMOOTH_FACTOR
local newRotation = Vector3.new(newDirection.X, newDirection.Y, newDirection.Z).Unit
bodyGyro.CFrame = CFrame.new(rootPart.Position, rootPart.Position + newRotation)

Aight, found the problem! At the end of the video, that emote i’ve played had a part in it and i forgot to put it as massless

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.