Well, here is my script that handles everything. For now, it justs make him stop on the tile and when he finishes turning it starts going to the next tile.
function Smooth_Turn(enemyModel, enemySpeed, cframe)
local tweenTime = (enemyModel.HumanoidRootPart.Position - Vector3.new(cframe.X, cframe.Y, cframe.Z)).Magnitude / enemySpeed
local info = TweenInfo.new(
tweenTime,
Enum.EasingStyle.Linear,
Enum.EasingDirection.Out,
0,
false,
0
)
print("ran the tween function")
local turnTween = TweenService:Create(enemyModel.PrimaryPart, info, {CFrame = CFrame.lookAt(enemyModel.HumanoidRootPart.CFrame, Vector3.new(cframe.X, cframe.Y, cframe.Z)})
turnTween:Play()
turnTween.Completed:Wait()
turnTween:Destroy()
end
function Move_Enemy(enemy, enemyID)
local enemyModel = workspace.Enemies[enemyID]
local pathOffset = enemyModel:GetAttribute("PathOffset")
local nodeAttribute = enemyModel:GetAttribute("Node")
local pathZOffset
for x, node in pairs(workspace.Path.Nodes:GetChildren()) do
if node:GetAttribute("Direction") == "Left" then pathZOffset = -pathOffset else pathZOffset = pathOffset end
local previousNode = workspace.Path.Nodes:FindFirstChild(tostring(x - 1)) or workspace.Path.StartNode
local nextNode = workspace.Path.Nodes:FindFirstChild(tostring(x + 1))
local nodeOffsetCFrame = node.CFrame * CFrame.new(pathOffset, enemy.HipHeight, pathZOffset)
local pnoc = previousNode.CFrame * CFrame.new(pathOffset, enemy.HipHeight, pathZOffset)
local distance = (nodeOffsetCFrame.Position - pnoc.Position).Magnitude
local tweenTime = distance / enemy.Speed
local tweenInfo = TweenInfo.new(tweenTime, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0)
local movementTween = TweenService:Create(enemyModel.PrimaryPart, tweenInfo, {CFrame = nodeOffsetCFrame})
movementTween:Play()
movementTween.Completed:Wait()
movementTween:Destroy()
if nextNode then
local nnoc = nextNode.CFrame * CFrame.new(pathOffset, 1, pathZOffset)
--Smooth_Turn(enemyModel, enemy.Speed, enemyModel.HumanoidRootPart.CFrame:Lerp(nnoc, 0.1))
workspace.Enemies[enemyID]:PivotTo(CFrame.lookAt(workspace.Enemies[enemyID].HumanoidRootPart.Position, Vector3.new(nnoc.X, nnoc.Y, nnoc.Z)))
else
enemyModel:Destroy()
table.remove(Database, enemyID)
end
end
end
and i know it isnt very optimized, but I tried doing the basics for optimizing.