I want this model to walk straight and not sometimes spin in place
like this
robloxapp-20240116-1850077.wmv (1.7 MB)
i already tried making the hip hight higher but it was still spinning
the AI script im using is
local teddy = script.Parent
local humanoid = teddy.Rex
teddy.PrimaryPart:SetNetworkOwner(nil)
humanoid:ChangeState(Enum.HumanoidStateType.None)
local function findTarget()
local players = game.Players:GetPlayers()
local maxDistance = 100
local nearestTarget
for index, player in pairs(players) do
if player.Character then
local target = player.Character
local distance = (teddy.HumanoidRootPart.Position - target.HumanoidRootPart.Position).Magnitude
if distance < maxDistance and not target:FindFirstChild("Hidden") then
nearestTarget = target
maxDistance = distance
end
end
end
return nearestTarget
end
local function getPath(destination)
local PathfindingService = game:GetService("PathfindingService")
local pathParams = {
["AgentHeight"] = 34,
["AgentRadius"] = 7,
["AgentCanJump"] = false
}
local path = PathfindingService:CreatePath(pathParams)
path:ComputeAsync(teddy.HumanoidRootPart.Position, destination.Position)
return path
end
local function attack(target)
local distance = (teddy.HumanoidRootPart.Position - target.HumanoidRootPart.Position).Magnitude
if distance > 20 and not target:FindFirstChild("Hidden") then
humanoid:MoveTo(target.HumanoidRootPart.Position)
end
end
local function walkTo(destination)
local path = getPath(destination)
if path.Status == Enum.PathStatus.Success then
for index, waypoint in pairs(path:GetWaypoints()) do
local target = findTarget()
if target and target.Humanoid.Health > 0 and not target:FindFirstChild("Hidden") then
print("TARGET FOUND", target.Name)
attack(target)
break
else
humanoid:MoveTo(waypoint.Position)
humanoid.MoveToFinished:Wait()
end
end
else
humanoid:MoveTo(destination.Position - (teddy.HumanoidRootPart.CFrame.LookVector * 10))
end
end
function patrol()
teddy.PrimaryPart:SetNetworkOwner(nil)
local waypoints = workspace.Rex1Way:GetChildren()
local randomNum = math.random(1, #waypoints)
local Distance = (teddy.HumanoidRootPart.Position - waypoints[randomNum].Position).Magnitude
walkTo(waypoints[randomNum])
end
while wait(0.25) do
patrol()
end
if u can help me please do.