I’m trying to lerp a model to my mouse but it keeps stuttering and delaying…
My code:
local function lerpModel()
for i = 0, 1, 0.05 do
local pos = Vector3.new(mouse.Hit.X,mouse.Hit.Y,mouse.Hit.Z)
wait()
placingModel:MoveTo(pos:lerp(Vector3.new(math.ceil(mouse.Hit.x), mouse.Hit.y, math.ceil(mouse.Hit.z)), i))
--placingModel:MoveTo(Vector3.new(math.ceil(mouse.Hit.x), mouse.Hit.y, math.ceil(mouse.Hit.z)))
end
end
mouse.Move:Connect(function()
if mouse.Target then
if mouse.Target == plot and mouse.TargetSurface == Enum.NormalId.Top then
wait()
lerpModel()
end
end
end)
Have a variable local changed = false, and in the for loop, have if changed then break end. Also, for the mouse.Move connection, after wait(), have a check: if not changed then changed = true end. Finally, make another connection: mouse.Idle:Connect(function() changed = false end). If you implement all this, it should work.
You are running the move function, which lasts 20 frames, every frame. There is your issue.
You can try using body mover instances to get the smooth movement I imagine you were trying to do, or reposition the model a fraction of the way every frame, though that sounds a little clunky.
Unanchor the model, put the body movers in the primary part of the model(usually an invisible part at the base of the mode). Every frame or two you set the body mover position to the mouse position
I’m using a BodyPosition and absolutely nothing happens except my Entire model falls apart and through the baseplate… It’s cancollide off if thats important.
local function positionModel()
placingModel.Hitbox.BodyPosition.Position = Vector3.new(mouse.Hit.X, mouse.Hit.Y, mouse.Hit.Z)
end
----------- [ EVENTS ] -------------
while placing == true do
wait()
if mouse.Target then
if mouse.Target == plot and mouse.TargetSurface == Enum.NormalId.Top then
wait()
positionModel()
end
end
end