Kart Controller Drifting System acting weird

Hi, im trying to recreate this drifting system from this game by @CasuallyCritical
https://www.roblox.com/games/13410992026/Octane-Rally-OUT-NOW

Which if i understand, what happens is that, whenever the drift starts, it automatically rotates a part, called the centerpoint (A part that dictates where the sphere (which rolls around to simulate kart behavior) goes and then adds speed according to the centerpoint’s RightVector and it rotates.

So I wrote this code:


local function lerp(A: number, B: number, D: number): number
	return A + (B - A) * D
end

local MaxRotation = 45


local function steer(deltaTime)
	steerDirection = 0 -- Default to no steering
	local rotationSpeed = 0 -- Default rotation speed

	-- Determine steering direction based on normal input
	if isTurningRight then
		steerDirection = 1
	elseif isTurningLeft then
		steerDirection = -1
	end

	-- Calculate the maximum rotation speed based on RealSpeed
	local maxRotationSpeed = math.clamp(MaxRotation - RealSpeed, 25, MaxRotation) -- Range: 2°/s to MaxRotation
	rotationSpeed = steerDirection * math.rad(maxRotationSpeed) * deltaTime -- Convert to radians and scale by deltaTime

	-- Handle Drifting
	if driftLeft or driftRight then
		rotationSpeed =  math.rad(maxRotationSpeed) * deltaTime
		if driftLeft and not driftRight then
			if isTurningLeft then
				rotationSpeed = math.rad(90) * deltaTime
			elseif isTurningRight then
				rotationSpeed = 0
			end
			
			if isSliding and TouchingGround then
				rotationSpeed = rotationSpeed * -1.05
			end
		elseif driftRight and not driftLeft then
			if isTurningRight then
				rotationSpeed = math.rad(90) * deltaTime
			elseif isTurningLeft then
				rotationSpeed = 0 
				
				-- Apply drift forces if sliding and touching the ground
				if isSliding and TouchingGround then
					rotationSpeed = rotationSpeed * 1.05
				end
			end
		end
	end
	
	
	if steerDirection ~= 0 or driftLeft or driftRight then
		CenterPoint.CFrame = CenterPoint.CFrame * CFrame.Angles(0, rotationSpeed, 0)
	end
end







local function move(deltaTime)
	RealSpeed = Sphere.CFrame:VectorToObjectSpace(Sphere.AssemblyLinearVelocity).Z

	Direction = Vector3.new(0,0,0)

	if isMovingForward then
		Direction = CenterPoint.CFrame.LookVector.Unit
		CurrentSpeed = lerp(CurrentSpeed, MaxSpeed, deltaTime * 0.5)
	elseif isMovingBackward then
		Direction = CenterPoint.CFrame.LookVector.Unit
		CurrentSpeed = lerp(CurrentSpeed, -MaxSpeed/ 1.75, 2 * deltaTime)
	else
		-- Decelerate when no input is given
		CurrentSpeed = lerp(CurrentSpeed, 0, deltaTime * 1.5)
	end
	
	if driftLeft then
		Direction = CenterPoint.CFrame.RightVector.Unit
	elseif driftRight then
		Direction = CenterPoint.CFrame.RightVector.Unit
	else
		Direction = CenterPoint.CFrame.LookVector.Unit
	end
end


local function drift(deltaTime)
	isSliding = true
	if DriftKeyPressed == true and TouchingGround == true then
		if steerDirection > 0 then
			driftRight = true
			driftLeft = false
		elseif steerDirection < 0 then
			driftLeft = true
			driftRight = false
		end
	end


	if DriftKeyPressed == true and TouchingGround == true and CurrentSpeed > 40 and steerDirection ~= 0 then
		driftTime += deltaTime
	end

	if DriftKeyPressed == true and CurrentSpeed < 40 then
		driftLeft = false
		driftRight = false
		isSliding = false

		driftTime = 0
	end

end



game:GetService("RunService").RenderStepped:Connect(function(dt)
	steer(dt)
	move(dt)
	drift(dt)
	print(CenterPoint.CFrame.LookVector.Unit)
	Sphere.AssemblyAngularVelocity = (Direction) * CurrentSpeed
end)

Here is me testing my own kart drifting controller:

Here’s me drifting around in the game:

it starts to turn too hard and spin then go back to normal, as if it doenst know what to do…