How would I tween orientation and position separately?

I’m currently using TweenService to linearly tween an object’s CFrame to the character’s CFrame, but the tweening of the orientation is very slow over long distances. This is because the time is dependent on the distance between the pet and the player to ensure that the pet is moving at a linear speed. However, this also means that the object’s orientation will move slowly if the distance is long (since the time to tween the orientation is increased over extended periods of time). Does anyone have any recommendations? I attempted to tween the part’s orientation, but this does not work as the part is welded and welds are ignored while an orientation is adjusted.

(petObj is the pet object and rootpart is the humanoid root part)

game:GetService("RunService").RenderStepped:Connect(function(dt)
	local Distance = (RootPart.Position - petObj.Position).Magnitude
	local Info = TweenInfo.new(Distance / 7)
	local NewCFrame = CFrame.lookAt(RootPart.Position, petObj.Position) 
	local Tween = TweenService:Create(petObj, Info, {CFrame = NewCFrame})
	Tween:Play()
end)
2 Likes

Not necessarily, no. Position is part of the singular property of CFrame. A solution to this is to have a goal that is a percent distance away from the final CFrame.

-- We will assume this is your final CFrame
local NewCFrame: (CFrame) = CFrame.lookAt(RootPart.Position, petObj.Position) 

-- Now, we'll want the rotation to be finished at 25% to the final CFrame
local partialGoal: (CFrame) = petObj.CFrame:lerp(NewCFrame, 0.25)
local finalOrientation: (CFrame) = (NewCFrame - NewCFrame.p)

-- Redefine the partial goal
partialGoal = CFrame.new(partialGoal.p) * finalOrientation

local Tween: (Tween) = TweenService:Create(petObj, Info, {CFrame = partialGoal})
Tween:Play()
Tween.Completed:Wait()

-- Now create another tween where the CFrame = NewCFrame to finish the distance

You’ll need to adjust your tween times to account for the percentage change

2 Likes

Thank you! I had a hunch, and this was well-articulated.