Hi. What I need to do is move a part from position A to exactly position B using RunService.Stepped. This page of the API shows an example of how to move a part, but I want it to stop at exactly one target point. Please help me.
[Edit] I can’t use TweenService because I need to animate many parts at the same time and every so often I need to know the intermediate state of all the parts at the same time. Sorry for not clarifying this.
Points A and B don’t change. It’s not an instantaneous movement (that’s why I use RunService). If I only check the CFrame I won’t get the exact target position.
local RunService = game:GetService("RunService");
local function MovePart(A,B, Part, Time)
local Start = tick();
while tick() < Start + Time do
Part.CFrame = CFrame.new(A:Lerp(B,(tick()-Start)/Time)) ;
RunService.Stepped:Wait();
end
Part.CFrame = CFrame.new(B);
end
local function onStep(_, deltaTime)
part.Position = part.Position + PART_SPEED * deltaTime
if part.CFrame == CFrameTarget then
-- disconnect stepped
end
end