MoveTo Roblox humanoid physics rendering

I am making an ai wave system which makes entities move simultaneously under a condition

Here is what the movement function looks like

local function UpdateMovement()
	if not workspace:GetAttribute("FightActive") then return end
	
	print("Start")
	
	for character in pairs(activeCharacters) do
		task.spawn(function()
			local humanoid = character:FindFirstChildOfClass("Humanoid")
			local root = character:FindFirstChild("HumanoidRootPart")
			if not humanoid or not root then return end
			local isEnemy = character:IsDescendantOf(Enemies)
			local targetFolder = isEnemy and Units or Enemies
			local target, dist = GetNearestTarget(character, targetFolder)
			if target and dist > STOP_DISTANCE then
				local targetRoot = target:FindFirstChild("HumanoidRootPart")
				if targetRoot then
					print("GOOO")					
					humanoid:MoveTo(targetRoot.Position)
				end
			end
		end)
	end
end

If i were to run this on an NPC which has never moved before (npcs spawn with hrp anchored btw) it would take 4 seconds of heartbeat looping to get the entity to move

Once it moves for the first time, the next wave it moves instantly

How can i make the physics render on the humanoid on spawn (content provider did nothing)

3 Likes

Hey!

Can you tell me where and how your NPCs are spawned? Also, could you provide me one of the NPC models as an rbxmx file so I could check out some properties as I might already know what’s causing it.

Also can you provide the part of your code that runs UpdateMovement()? It’ll help figuring out what’s going on, on your end. Try spawning your NPCs with HumanoidRootPart.Anchored = false.

1 Like

NPCs shouldn’t be anchored, otherwise they won’t move at all. Perhaps another part of your code unanchors the HRP.

You could also add prints to see whether the if statements are going through. If they’re printing but the NPC isn’t moving, then it’s not a code problem.

if target and dist > STOP_DISTANCE then
	local targetRoot = target:FindFirstChild("HumanoidRootPart")
	if targetRoot then
		print("GOOO")					
		humanoid:MoveTo(targetRoot.Position)
	else
		print("1")
	end
else
	print("2")
end

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