function zomb.Move(Zombie)
local speed = Zombie.cfg.Speed.Value * 100
local pathway = workspace.pathway
local BezierPath = require(workspace.BezierPath)
local waypoints = {pathway.Spawn.Position}
local offset = math.random(-1,1)
local movingto = Zombie.waypoint
for i = 1, #pathway:GetChildren() - 2 do
table.insert(waypoints, pathway[i].Position)
end
table.insert(waypoints, pathway.Exit.Position)
local NewPath = BezierPath.new(waypoints,4)
local HumanoidRootPart = Zombie.HumanoidRootPart
for t = 0,1,1/speed do
HumanoidRootPart.CFrame = NewPath:CalculateUniformCFrame(t) * CFrame.new(offset, HumanoidRootPart.Size.Y * 1.5, 0)
task.wait(0.01)
end
workspace.map.Base.Humanoid:TakeDamage(Zombie.Humanoid.Health)
Zombie:Destroy()
end
I’m using BezierPath to move all my Zombies
All zombies are anchored
movingto variable is an int value
I tried using touched event, but it didn’t work for some reason
for i, wp in path:GetWaypoints() do
local part = Instance.new("Part")
part.Shape = "Ball"
part.Material = "Neon"
part.Size = Vector3.new(.1,.1,.1)
part.Position = wp.Position + Vector3.new(0,2,0)
Now you can just use a touched event on these parts.
for i,v in pairs(pathway:GetChildren()) do
local distance = (HumanoidRootPart.Position - v.Position).Magnitude
local closest = nil
if not closest or distance < closest then
closest = distance
print(closest)
end
end
I tried the second method and it doesnt work, it prints out all the children inside pathway instead
Touched events do work whether the part is anchored or not, what determines if the event is triggered is the cantouch property.
Also why use CFrames to move the zombies? Using :MoveTo() would be much more effective.
The method of lerping CFrames and what not is for models that have alot of baseparts and therefore using regular methods would be laggy. However, a typical zombie NPC would work fine with moveto.
Tons of games use the simple moveto on NPCs and they experience no issues whatsoever, if you want it to be smooth you can mess around with network ownership.
I just found using cframes more optimized than moving all the zombies with humanoid:MoveTo() because I plan to make big hordes of zombies and I don’t want big impact on FPS
local parts = Zombie["Left Leg"]:GetTouchingParts()
for _, part in pairs(parts) do
for _, pathwayPart in pairs(pathway:GetChildren()) do
if part == pathwayPart then
Zombie.MovingTo.Value += 1
end
end
end