Hello,
I am making a TD game. So I am working on the AI. It all worked perfectly. But I need an alternative to this line right here:
if i > 0 then
local at = zombie.HumanoidRootPart.Position
local lookAt = destination.Position
local cframe = CFrame.lookAt(at,lookAt)
local tween = TweenService:Create(zombie.HumanoidRootPart.BodyGyro, TweenInfo.new(0.5), {CFrame = cframe})
tween:Play()
tween.Completed:Wait()
end
It’s making the zombie turn slowly. Any alternative to make the zombie turn with waiting until tween.Completed:Wait()
?
if i > 0 then
task.spawn(function()
local at = zombie.HumanoidRootPart.Position
local lookAt = destination.Position
local cframe = CFrame.lookAt(at,lookAt)
local tween = TweenService:Create(zombie.HumanoidRootPart.BodyGyro, TweenInfo.new(0.5), {CFrame = cframe})
tween:Play()
tween.Completed:Wait()
end)
end
not sure if this is what you want but here
it’s not working. here is the whole script:
local TweenService = game:GetService("TweenService")
local zombie = script.Parent
local map = workspace.Map
local paths = map.Paths
local bodyGyro = zombie.HumanoidRootPart.BodyGyro
bodyGyro.CFrame = zombie.HumanoidRootPart.CFrame
for i=1, #paths:GetChildren() do
local destination = paths[i]
if i > 0 then
task.spawn(function()
local at = zombie.HumanoidRootPart.Position
local lookAt = destination.Position
local cframe = CFrame.lookAt(at,lookAt)
local tween = TweenService:Create(zombie.HumanoidRootPart.BodyGyro, TweenInfo.new(0.5), {CFrame = cframe})
tween:Play()
tween.Completed:Wait()
end)
end
local distance = (zombie.HumanoidRootPart.Position - destination.Position).Magnitude
local tweenInfo = TweenInfo.new(
distance/zombie.Humanoid.WalkSpeed,
Enum.EasingStyle.Linear,
Enum.EasingDirection.InOut,
0,
false,
0)
local offset = (zombie.HumanoidRootPart.Size.Y/2) + zombie["Left Leg"].Size.Y - 0.5
local goal = {CFrame = destination.CFrame * CFrame.new(0,offset,0)}
local tween = TweenService:Create(zombie.HumanoidRootPart, tweenInfo, goal)
tween:Play()
tween.Completed:Wait()
end
print("An enemy has damaged the base.")
zombie:Destroy()
nevermind… I stop using tween and replace it with
if i > 0 then
local at = zombie.HumanoidRootPart.Position
local lookAt = destination.Position
local cframe = CFrame.lookAt(at,lookAt)
bodyGyro.CFrame = cframe
wait(0.1)
end
so yeah. that’s all