How can I make a smooth placement?

The code is

local primary = sampleModel.PrimaryPart

for i = 0.01, 1, 0.01 do
	task.wait()
	local goal = unit.Main.CFrame + Vector3.new(0, 1, 0)
				
	sampleModel:SetPrimaryPartCFrame(primary.CFrame:Lerp(goal, i))
end	

But it acts so weirdly on this video

How could I fix that?

You can do sampleModel:PivotTo(primary.CFrame:Lerp(goal, deltaTime * 10)
(SetPrimaryPartCFrame is deprecated. “deltaTime” is the time between each frame.)

1 Like

what exactly would be a deltaTime? i ?

Like this:

game:GetService("RunService").RenderStepped:Connect(function(deltaTime)
--This function fires every frame the game steps. Delta time is the time it takes to do that.
end)

this?

local primary = sampleModel.PrimaryPart

local goal = unit.Main.CFrame + Vector3.new(0, 1, 0)
				
game:GetService("RunService").RenderStepped:Connect(function(deltaTime)
	sampleModel:PivotTo(primary.CFrame:Lerp(goal, deltaTime * 10))
end)

If I do like that it does first move good, then just kinda stops and start vibrating
I should have said that it’s inside a MouseEnter function

Oh. Move it out of there. Create a separate CFrame variable like local cf = CFrame.new() then adjust that to the goal in the mouse enter function.

Then, you put this outside the mouse enter.

It worked! The thing I am wondering about though is optimisation, it won’t drop very much right?

Of course not, unless of course you already have many loops.

Additionally, you might want to update other stuff here in the same loop, which might make it more performant as you keep developing the system.

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