I’m trying to make my character turn, but whenever I do it decides to flip and I don’t quite know how to fix it.
hrp.CFrame = CFrame.lookAt(hrp.Position, Vector3.new(Nodes[index+1].Position.X,hrp.Position.Y,Nodes[index+1].Position.Z)) -- Works over here
local distance = (Nodes[index].Position - Nodes[index+1].Position).Magnitude
local timeToGetThere = distance/self.WalkSpeed
local subNodes = math.floor(distance) / 0.5
for subNode = 0,subNodes do
local subNodePos = CFrame.new(Nodes[index].Position.X,hrp.Position.Y,Nodes[index].Position.Z):Lerp(CFrame.new(Nodes[index+1].Position.X,hrp.Position.Y,Nodes[index+1].Position.Z),subNode/subNodes)
local nextNodePos = CFrame.new(Nodes[index].Position.X,hrp.Position.Y,Nodes[index].Position.Z):Lerp(CFrame.new(Nodes[index+1].Position.X,hrp.Position.Y,Nodes[index+1].Position.Z),((subNode+1)/subNodes))
hrp.CFrame = subNodePos * CFrame.Angles(0,math.rad(hrp.Orientation.Y),0) -- My guess is something over here bugging it?
nextNodePos *= CFrame.Angles(0,math.rad(hrp.Orientation.Y),0)
if subNode ~= subNodes then
enemyMovementRemote:FireAllClients(hrp,timeToGetThere/subNodes,nextNodePos)
else
enemyMovementRemote:FireAllClients(hrp,timeToGetThere/subNodes, CFrame.lookAt(hrp.Position, Vector3.new(Nodes[index+1].Position.X,hrp.Position.Y,Nodes[index+1].Position.Z)))
end
-- Doesn't work over here
task.wait(timeToGetThere/subNodes)
end