Hi there,
I’m using Quenty’s spring module to make a spring-based camera system however I’ve run into an issue when the character rotates 180 degrees - rather than the camera smoothly turning from a rotation of 180 degrees to 181 degrees, the camera will instead reach that angle by travelling along the rotation axis in the other direction as you can see by this video:
I think this is caused by the fact the spring module lerps between to values, and you can’t lerp with any values past 180 degrees as beyond that the angle values are negative (like -pi).
Is there anyway to workaround this (i.e. get the module to transition between negative and positive rotations)?
Here’s the code:
(P.S. sorry for poor formatting haven’t used this forum for a long time lol)
local positionSpring = Spring.new(Vector3.new())
local anglesSpring = Spring.new(Vector3.new())
positionSpring.Damper = 0.6
positionSpring.Speed = 2
local function CFrameToVector3(cframe: CFrame)
local position = cframe.Position
local angles = Vector3.new(cframe:ToEulerAnglesYXZ())
return position, angles
end
local function Vector3toCFrame(vector3: Vector3, angles)
local newCFrame = CFrame.fromEulerAnglesYXZ(angles.X, angles.Y, angles.Z)
newCFrame = CFrame.new(vector3) * newCFrame
return newCFrame
end
workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
connObj = RunService.Heartbeat:Connect(function()
local targetCFrame = rootPart.CFrame * CFrame.new(d.x, d.y, d.z)
local position, angles = CFrameToVector3(targetCFrame)
angles.Target = angles
positionSpring.Target = position
local newSpringPosition = positionSpring.Position
local newSpringAngles = anglesSpring.Position
workspace.CurrentCamera.CFrame = Vector3toCFrame(newSpringPosition, newSpringAngles)
end