i just finished my tower defense zombie movement, but when i try to spawn a boss, i added a function to rotate the zombie to the node, but sometimes the boss goes too far and is just stuck in that rotation, it’s not a bug, i just want to know how would i fix this?
movement code:
sorry for bad and messy code.
local root = script.Parent.HumanoidRootPart
local path = game.Workspace.path
local TweenService = game:GetService("TweenService")
local config = script.Parent.Config
local node = path
script.Parent.HumanoidRootPart.CFrame = CFrame.new(game.Workspace.spawn.CFrame.X, game.Workspace.spawn.CFrame.Y+1.2, game.Workspace.spawn.CFrame.Z)
-- beginning
local info = TweenInfo.new(0.1, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false, 0)
local tween = TweenService:Create(root, info, {
CFrame = CFrame.new(root.Position, node.Position+Vector3.new(0,root.Size.Y,0))
})
tween:Play()
tween.Completed:Wait()
local dist = (root.CFrame.Position - node.CFrame.Position).magnitude
local speed = config.Speed.Value
local Time = dist/speed
local info = TweenInfo.new(Time, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false, 0)
local size = script.Parent.HumanoidRootPart.Size.Y/2+script.Parent["Left Leg"].Size.Y-0.5
local tween = TweenService:Create(root, info, {
CFrame = CFrame.new(node.CFrame.Position.X, node.CFrame.Position.Y+size, node.CFrame.Position.Z) * CFrame.fromEulerAnglesXYZ(root.CFrame:ToEulerAnglesXYZ())
})
tween:Play()
tween.Completed:Wait()
-- middle
for i, v in pairs(path:GetDescendants()) do
node = v
local info = TweenInfo.new(0.1, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false, 0)
local tween = TweenService:Create(root, info, {
CFrame = CFrame.new(root.Position, node.Position+Vector3.new(0, root.Size.Y, 0)) -- here it is
})
tween:Play()
tween.Completed:Wait()
local dist = (root.CFrame.Position - node.CFrame.Position).magnitude
local speed = config.Speed.Value
local Time = dist/speed
local info = TweenInfo.new(Time, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false, 0)
local size = script.Parent.HumanoidRootPart.Size.Y/2+script.Parent["Left Leg"].Size.Y-0.5
local tween = TweenService:Create(root, info, {
CFrame = CFrame.new(node.CFrame.Position.X, node.CFrame.Position.Y+size, node.CFrame.Position.Z) * CFrame.fromEulerAnglesXYZ(root.CFrame:ToEulerAnglesXYZ())
})
tween:Play()
tween.Completed:Wait()
local decoy = node
node = decoy:GetChildren()[1]
print(node.Name)
end
working:
glitch:
you can see in the picture that the zombies humanoid is tilted to the node.