Hello. I am trying to make a tower defense game and i am currently in the stage of making the zombies move. The way i am doing that is through a script that modifies the zombie's rotation and position once it hits a corner part. The problem is, the rotation the script sets is not relative, but it is absolute. Here is my script
local myZombie = script.Parent
print("Myzombie Defined")
while wait(0.3333) do --The server zombies update position thrice per second
myZombie:SetPrimaryPartCFrame(myZombie.HumanoidRootPart.CFrame*CFrame.new(0,0,-myZombie.ZombieSpeedSPS.Value/3))
print("Zombie advances")
collidelist = myZombie.HumanoidRootPart:GetTouchingParts() --get parts touching
for i=1, #collidelist do
if collidelist[i].Name == "BendWP" then --if part is corner part
myZombie:SetPrimaryPartCFrame(CFrame.new(collidelist[i].ReferencePart.Position.X, 1.7, collidelist[i].ReferencePart.Position.Z)) -- as the zombie position update is so slow, i adjust its position to correct overshoots and undershoots
if collidelist[i].IsRightBend.Value == true then --if part mandates to turn right
local cframe = myZombie.PrimaryPart.CFrame -- Current CFrame
myZombie:SetPrimaryPartCFrame(cframe * CFrame.new(0, math.rad(90), 0))
else--Else
local cframe = myZombie.PrimaryPart.CFrame -- Current CFrame
myZombie:SetPrimaryPartCFrame(cframe * CFrame.new(0, math.rad(-90), 0))
end
end
end
end
PD: It is a model

2 comments
I also tried CFrame.Angles and it did not work either
Does the zombie have a humanoid? If so, use pathfinding and humanoid:MoveTo(). This will automatically make him turn left / right