I’m trying to make the the current part follows the target rotation but it rotates in a very wrong and reversing way. When I tried to do full circle motion, it acts really weird. How do I fix this?
And here is the code I wrote
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Spring = require(ReplicatedStorage.Spring)
local RunService = game:GetService("RunService")
local TargetPart = workspace.TargetPart
local CurrentPart = workspace.CurrentPart
local SpringPos = Spring.new(Vector3.new())
local SpringRot = Spring.new(Vector3.new())
local Offset = CFrame.new(0,0,5)
local function getPositionAndAnglesFromCFrame(cf)
return cf.Position, Vector3.new(cf:ToOrientation())
end
RunService.Stepped:Connect(function()
local TargetPart_position, TargetPart_angles = getPositionAndAnglesFromCFrame(TargetPart.CFrame)
-- Added spring for a target position
SpringPos.Speed = 10
SpringPos.Damper = 10
-- Added spring for a target rotation
SpringRot.Speed = 10
SpringRot.Damper = 10
SpringPos.Target = TargetPart_position
SpringRot.Target = TargetPart_angles
CurrentPart.CFrame = CFrame.new(SpringPos.Position) * CFrame.Angles((SpringRot.Position.X) , (SpringRot.Position.Y) , (SpringRot.Position.Z)) * Offset
end)
It would be helpful if you would tell me where the problems are.