How would I make a pathfinding NPC climb objects?

I rigged up a monster and finally got most of the scripting to work, but I want it to be able to climb objects. I know this is possible to do because it is done in other horror games like
THE RAKE™: Classic Edition | v1.1.2c.

Whenever I set the waypoint on top of this structure, it doesn’t seem to understand how to climb the ladder:

Am I missing out on something here?

4 Likes

How on ear Th did you make a path findinf NPC!?
The answer to your question I would think is, is there a animation for it to climb up? Does acertain part of the monster have to touch the “ladder” for it to realize it can climb it? Are you sure your npc can even climb things if it wasent a monster?

1 Like

Sorry for my garbage stain spelling.

1 Like

I did not make an animation for climbing, but I don’t think that would be the problem. I assumed that the HumanoidRootPart would detect it to climb automatically on it’s own. I’m pretty sure it’s possible, because I’ve seen other games do it before.

Maybe you should move humanoid root part to the head. Idk if that’s possible but it’s worth a shot :sweat:

1 Like

I understand you originally wanted the NPC to climb the ladder but, given it’s very tall height, I think giving it a high jump ability could be worth wild.

1 Like

I dont think it will work automatically as there are only 2 actions available from pathfinding waypoint action (at least for now) which is walk and jump.

1 Like

Yes I suppose jumping is a mutch better use, I understand this may not give that feeling you were hoping for

1 Like

I was planning on adding a metal tower that players could go on and the monster could scale the metal beams and climb to the top to make it scarier, but jumping could work if I had resort to it.

I completely agree, I am so sorry that this won’t work. I hope some laughs genius will help you because I would LOVE to play your game :slight_smile: keep up the great ideas and work

1 Like

If you are using the PathFindingService, you may want to use the blocked event part of the Path.

If this triggers the blocked event, you could check if it’s there’s a ladder nearby with a ray cast and then if there is, you can manually make it climb the ladder. Once at the top, you can recalculate the path to the object.

3 Likes

This is definitely a step in the right direction, but what do you mean by “manually climbing the ladder”? Would you suggest making the monster walk to the base of the ladder and then make a function that plays a climbing animation and tweens his body to the top of the ladder?

Exactly. When I said manually, I mean you having to make it go up the ladder by scripting it yourself like animating, tweening and detecting when at the top of the ladder. There may be some bugs doing this if they arent exactly at the ladder. You may want to check for Z differences between the object and the monster as well to determine if they are higher than the monster and then check for a nearby ladder which would have the bottom of the ladder near the same Z as the monster. The reason for this distinction is that you may have a tower with multiple ladders and maybe you want your monster to be able to climb two sets of ladders to keep going up.

1 Like

I might continue with my idea of the monster being able to scale any part of the tower and not just ladders. That way, if it is chasing a player that is above it, it can instead check if the tower is in front of it and then continue with your idea of tweening the body upwards and playing the climbing animation regardless of where it is at the base of the tower so I won’t have to worry about it detecting multiple ladders.

I’m not sure if any of that made any sense, but it’s gonna be a little complicated. I think I will be able to make it work with your solution, though. Thanks!

That seems like a reasonable solution without the complexity of multiple ladders. As well removes the issue of what if he walks into the tower and the ladder is on the other side of the tower. Good luck with your game.

1 Like

Could you kindly share the final solution If any?

I am having a hard time on climbing too. I made an NPC that follows player. However it can’t climb up a tower to follow.

Much appreciated.

1 Like

This code is gonna seem extremely messy because I had to do a ton of trial and error with it, but here’s what I used:

local NPC = script.Parent
local ClimbAnim= humanoid:LoadAnimation(script:WaitForChild("Climb"))
local climbdebounce = false
local Tower = workspace.Tower --Change to whatever your tower is named

local function climbTower()
	if NPC.HumanoidRootPart.Position.Y < Tower.BottomPoint.Position.Y + 5 and climbdebounce == false then --If the NPC is on the ground and isn't climbing then
		climbdebounce = true
		NPC.HumanoidRootPart.Anchored = true --Must be done for tweening
		NPC.HumanoidRootPart.CFrame = CFrame.new(NPC.HumanoidRootPart.Position, Tower.BottomPoint.Position) --Turns the NPC to face the tower's center
		
		--Tweening stuff starts here
		local info = TweenInfo.new(
			3, --Time it takes to complete tween
			Enum.EasingStyle.Linear,
			Enum.EasingDirection.In
		)
		local goals = {
			CFrame = CFrame.new(NPC.HumanoidRootPart.Position + Vector3.new(0, Tower.Main.Size.Y + 4, 0)) * (NPC.HumanoidRootPart.CFrame - NPC.HumanoidRootPart.Position)
		}
		TweenService:Create(NPC.HumanoidRootPart, info, goals):Play()
		--Basically plays the tween and sets parameters ^^^
		
		ClimbAnim:Play()
		wait(3)
		ClimbAnim:Stop()
		wait(.2)
		NPC.HumanoidRootPart.Anchored = false
		climbdebounce = false
	end
end

--This is what causes the function to run when the "Main" part is touched:
function onTouched(hit)
	climbTower()
end

Tower.Main.Touched:connect(onTouched)

It might seem very confusing, but you basically need the following:

  1. Tower to be grouped into a model
  2. Tower to have an invisible part positioned at the bottom center of the tower named “BottomPoint” inside the model
  3. Tower to have a part named “Main” inside the model that envelopes the entire tower and has no collision for the touch function
  4. A climbing animation inside the script

The monster for my game is able to climb any part of the tower, so if you want it to only be able to climb a certain part of it (like just the ladder), you would probably have to change a few things in the script and make the “Main” part envelope only the ladder and not the entire tower.

4 Likes

How would you know the size of ladder and the player could even jump behind when climbing and how do you make a npc climb half the ladder and jump back like obby

Character Pathfinding | Roblox Creator Documentation

Make sure the HumanoidRootPart is not collidable.

Gotta bump this ince I really ned to know