karta333
(pro)
January 21, 2025, 6:52pm
#1
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
avodey
(avocado)
January 21, 2025, 7:08pm
#2
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
I decided to write a module for handling linear interpolation, as I find myself needing it pretty frequently. I assume you, the reader, might also benefit from this, so I attached the code.
If you don’t know what linear interpolation is, it’s smoothly transitioning from one value to the next.
Here’s the syntax
Lerp(rbx, prop, target, duration?, callback? easingStyle?, easingDirection? is_relative?)
rbx: the object you are targeting.
prop: the property you want to smoothly change.
target: th…
This is what you’re looking for, I think
karta333
(pro)
January 21, 2025, 8:31pm
#4
Thanks, that’s what i was looking for
system
(system)
Closed
February 4, 2025, 8:31pm
#5
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.