I dont know whats going on But My custom character started spinning when used MoveTo()

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.

The Humanoid HipHeight is probably too low, try raising it.

No, it didn’t work its still spinning

Make sure when you change the HipHeight, you can visibly see the character floating. It is most likely spinning because it is being shoved into the ground slightly

–Edit–
I’m blind I didn’t see that video sorry. Reviewing the script now

It looks like the rex is choosing waypoints that are right next to each other, and because it’s so big that when it moves like 2 studs, it turns into a tornado. Maybe try

function patrol()
repeat
	teddy.PrimaryPart:SetNetworkOwner(nil)
	local waypoints = workspace.Rex1Way:GetChildren()
	local randomNum = math.random(1, #waypoints)
	local Distance = (teddy.HumanoidRootPart.Position - waypoints[randomNum].Position).Magnitude
    if Distance >= 10 then
	    walkTo(waypoints[randomNum])
    end
until Distance >= 10

end

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.