Trying to rotate a player's head a full 360 degrees

Hi, so I’m currently trying to add a spin animation on the player’s head. For whatever reason, when I specify the amount of rotation to about 360, nothing happens. If it’s a smaller number, then it works, but it doesn’t go for the whole 360 degree rotation I’m looking for.

tween_service:Create(headMotor, TweenInfo.new(.3), {C1 = headMotor.C1*CFrame.Angles(0, math.rad(360), 0)}):Play()

headMotor being a Motor6D.

Not really sure what to try here. Any help appreciated, thanks. :slight_smile:

As it’s current state is actually 360 degrees, I mean the same orientation, I think it’s because tweenservice will not tween to equal values
though you can do

local t = tween_service:Create(headMotor, TweenInfo.new(.3), {C1 = headMotor.C1*CFrame.Angles(0, math.rad(359), 0)})
t:Play()
t.Completed:Wait()
 tween_service:Create(headMotor, TweenInfo.new(.06), {C1 = headMotor.C1*CFrame.Angles(0, math.rad(1), 0)}):Play()
1 Like

That actually doesn’t rotate the head at all as well though. :confused:

Then try tweening the C0, have you tried that?

I just tried, and it’s doing the same thing. I’ve input a high value, like 350, and it rotates nowhere near that rotation in total…

1 Like

As stated before, TweenService will always take the shortest path possible to rotating. Something you could do is do a bunch of smaller tweens that actually take the correct path:

for i=1, 4 do
local nt = tween_service:Create(headMotor, TweenInfo.new(.0.075), {C1 = headMotor.C1*CFrame.Angles(0, math.rad(i * 90), 0)})
nt:Play()
nt.Completed:Wait()
end

I think this would work?

2 Likes

It seems at though its taking the quickest route towards its goal. Meaning either clockwise or counter-clockwise depending on what’s faster. 180 degrees would always get you the maximum rotation.

So how to fix this: tween your rotation in steps of 180 degrees.

local function tweenRotation(rotation,duration)
	local steps = math.floor(rotation / math.pi);
	local excess = rotation - math.pi * steps;
	local durationPerRadian = duration / rotation;

	for i=1,steps do
		local goal = {C1 = headMotor.C1 * CFrame.Angles(0,math.pi,0)}
		local currTween = tweenService:Create(headMotor,TweenInfo.new(math.pi * durationPerRadian,Enum.EasingStyle.Linear) ,goal);
		currTween:Play()
		currTween.Completed:Wait()   
	end

	-- Account for excess rotation
	local goal = {C1 = headMotor.C1 * CFrame.Angles(0,excess,0)}
	tweenService:Create(headMotor,TweenInfo.new(excess * durationPerRadian),goal):Play();  
end

Edit: Made a bunch of typos, cause I was typing this really fast and on mobile. Another thing I forgot to mention was that this approach would only work if you using a linear tween of course.

3 Likes

Something I usually do when trying to tween rotations like this is I create a temporary NumberValue that acts as the degree and tween that instead. It should be something like this:

local angle = Instance.new("NumberValue")

RunService.Heartbeat:Connect(function()
    headMotor.C1 = CFrame.new(headMotor.C1.Position) * CFrame.Angles(0, math.rad(angle.Value), 0)
end)

TweenService:Create(angle, tweenInfo, {
    Value = 360;
}):Play();

[EDIT 1/7/2022]: Instead of using NumberValues and tweening them, it would probably work better to use a spring.

5 Likes