Questions on NPCs

I am starting to learn NPCS and how they work tommrow. BUT before I do, I have some questions on how to make them and stuff.

  1. How would I make the NPC follow players, go to certain positions effectively? I know about pathfinding but if there are any other ways to do it please tell me.

  2. How would I rig NPCS, I made a dinosaur NPC today and I am wondering how I would rig it

  3. How would pathArgs work?

4.How would I make npcs run animations.

I made a script on a NPC, it is supposed to be following the player but it isn’t. Here is the script

local humanoid = script.Parent:WaitForChild("Humanoid")
local NPCRootPart = script.Parent:WaitForChild("HumanoidRootPart")
local NPC = script.Parent
local PathfindingService = game:GetService("PathfindingService")


--[[local pathArgs = {
	["AgentHeight"] = 13.43,
	["AgentRaidus"] = 3,
	["AgentCanJump"] = true
}--]]

function moveToPlayer()
	local characters = game.Workspace:GetChildren("Model")
	if characters ~= NPC and characters.HumanoidRootPart and characters.Humanoid then
		local magnitude = (NPCRootPart.Position - characters.HumanoidRootPart.Position).Magnitude
			local path = PathfindingService:CreatePath()
		path:ComputeAsync(NPCRootPart.Position,characters.HumanoidRootPart.Position)
		local waypoints = path:GetWayPoints()
		for _, waypoint in pairs(waypoints) do
			if waypoint.Action == Enum.PathWaypointAction.Jump then
				humanoid.Jump = true
			end
			if magnitude <= 20 then
			humanoid:MoveTo(waypoint.Position)
			humanoid.MoveToFinished:Wait(0.5)
			end
		end
	end
end

while wait(1) do
	moveToPlayer()
end
3 Likes

Also about the pathArgs how would I get the radius and height.

So you want the NPC to both follow players and go to certain positions effectively?

This process can be a bit complicated, but just imagine the dinosaur body parts are the R6/R15 parts. Then you have to connect the parts that can be animatable with Motor6Ds.

Pathfinding:CreatePath() can take one argument, which is a dictionary for the arguments.

EXAMPLE:

local PathParams = {
    “AgentRadius” = 5;
    “AgentHeight” = 3;
    “AgentCanJump” = false
}

You can just copy the Animate local script from your character. Then, you copy the whole code inside the local script and paste it in a server script, then move all of the children’s of the Animate local script to the server script. Then to change their Animation ID, you copy your custom animation ID and replace the ID’s inside the Animation Instance inside the animations.

Thank you. For when the npc is following should I use the humanoid root part of the npc to the humanoid root part of the player?

Yes, since whatever PrimaryPart in a model is the core of everything inside the model.