I’ve tried lerping and using the SetPrimaryPartCFrame
function of models, but the movement is very choppy. My script uses path finding as well, so I think the problem may be there as well.
Here’s my script:
-- changing positions
local iterations = math.abs((hitBox.Position - Vector3.new(pos)).magnitude)/100
for i = 0, 1, iterations/math.floor(10^math.log10(iterations)*10) do
self.model:SetPrimaryPartCFrame(hitBox.CFrame:Lerp(pos, i))
wait(1/100)
end
-- pathfinding
local character = player.Character or player.CharacterAdded:Wait()
local hitBox = self.model.HitBox
local startPos = hitBox.Position
local endPos = character.PrimaryPart.Position
local path = PathfindingService:CreatePath({
["AgentRadius"] = math.clamp(hitBox.Size.X + hitBox.Size.Y + hitBox.Size.Z, .2, .5),
["AgentHeight"] = math.clamp(hitBox.Size.Y, .5, 3),
["AgentCanJump"] = false,
})
local created, newPath = pcall(function()
return path:ComputeAsync(startPos, endPos)
end)
if created then
local waypoints = path:GetWaypoints()
for _, waypoint in ipairs(waypoints) do
local moveToSuccess, err = pcall(function()
return self:MoveTo(CFrame.new(waypoint.Position))
end)
if not moveToSuccess then
warn(err)
end
end
end