Detecting when a part has made a full rotation on it's axis

I’m having some difficulty predicting when a part has completely rotated on one of it’s axis.
It can be tricky because I need something that is dynamic, and can be suitable for any speed at which the part is rotating. Right now I get the percentage that the part has rotated to 360 degrees, and then see if it’s above or equal to 100, and if it is, it’ll count it as a complete rotation. However, there is a problem with this, say the rotation speed is so quick that the percentage makes a jump between 99% and 1%, then it’ll never consider a full rotation on it’s axis. (this gap could be even bigger depending on how quick it’s rotating).

I can see how what I just explained may be a bit confusing but I’ll do my best to answer any questions. I’ll show code if necessary.

1 Like

Bumping post up. Don’t mind me.

Any help? Just want to make sure my post doesn’t get drowned.

Well after some tinkering with my original code, I fixed my problem. For anyone who comes across this post and is wondering the same, here is a breakdown of the code with comments:

local RunService = game:GetService("RunService")

-- Initial rotation speed and time multiplier
local baseRotationSpeed = 90
local timeMultiplier = 1
local part = script.Parent

local totalRotation = 0

local function update(deltaTime)
	local adjustedRotationSpeed = baseRotationSpeed * timeMultiplier
	local deltaRotation = baseRotationSpeed * deltaTime
	part.CFrame = CFrame.Angles(0, totalRotation + deltaRotation, 0) -- Rotating around the Y-axis

	totalRotation = totalRotation + math.abs(deltaRotation)

	-- Check if the part has completed a full rotation (360 degrees)
	if totalRotation >= 2 * math.pi then -- Use 2 * math.pi for a full rotation in radians
		print("Part completed a full rotation!")
		totalRotation = 0

-- Connect the update function to the Heartbeat event
1 Like

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