I have had a difficult time understanding the concepts that have been presented while searching for the answer to this, such as using quaternions. I have no idea how to apply them. Any help would be highly appreciated.
This is ripped in its entirety from the Roblox wiki article "Springs", just edited to be used with rotation.
local rs = game:GetService("RunService") local cc = workspace.CurrentCamera local spring = {} function spring.new(current, velocity, target) local self = setmetatable({}, {__index = spring}) self.current = current self.velocity = velocity self.target = target self.k = 1 self.d = 1 return self end function spring:update() local x = self.target - self.current local f = x * self.k self.velocity = (self.velocity * (1 - self.d)) + f self.current = self.current + self.velocity end local part0 = Instance.new("Part", workspace) part0.Anchored = true part0.CanCollide = false local part1 = Instance.new("Part", workspace) part1.Anchored = true part1.CanCollide = false local new = spring.new(part0.Orientation, Vector3.new(), part1.Orientation) new.k = 0.5 new.d = 0.5 rs.RenderStepped:connect(function() new.target = part0.Orientation new:update() part0.CFrame = cc.CFrame part1.CFrame = part0.CFrame * CFrame.new(-2, -2, -5) part1.Orientation = new.current end)
Ok, I don't have the time to finish the script. Basically what I was going to do was make it measure the distance between the rotations. If its over 180deg, it reverses the angle.
(the problem being that roblox doesn't naturally loop from 180 over to -180, you have to do that math yourself. So if the last angle is 180, and the next angle is supposed to be -170 it will go backwards. You want to tell it to keep going those remaining degree instead of backtracking.
Radians since they work in relation to a circle itself would be my preferred rout if I had time to do the math. Especially since they auto fill if you add or subtract with them.
You could also use axis rotations I think, it would require more math though i think..