How to give easing style to part when using .Heartbeat?

What I’m trying to achieve is i want to animate part position simillar to how tween service does it but without using tween service. Because my part is inside runservice and it doesn’t really work that well

(My script

local Pet = pet:Clone()
Pet.CanCollide = false
Pet.Anchored = true

local offset = CFrame.new(2, 1, 2)


local connection
local function StartFollow()
	connection = runservice.Heartbeat:Connect(function()
		Pet.CFrame = char.PrimaryPart.CFrame * offset
	end)
end
2 Likes

You can’t tween without using TweenService. Do you want to interpolate?

local Pet = pet:Clone()
Pet.CanCollide = false
Pet.Anchored = true

--\\ Constants

local PET_OFFSET = CFrame.new(2, 1, 2)
local SPEED = 9

--\\ Connections

local connection: RBXScriptConnection do
	connection = runservice.Heartbeat:Connect(function(dt: number)
		local goalCFrame = char:GetPivot() * offset
		Pet.CFrame = Pet.CFrame:Lerp(goalCFrame, math.min(1, dt * SPEED))
	end)
end

This will move the pet closer and closer to the target position over time. The SPEED variable determines how quickly it does that.

2 Likes

This is what you’re looking for, I think

Thanks, that’s what i was looking for :upside_down_face:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.