Is this even possible as an NPC?

I’ve been trying this for quite a while, probably made 5 posts about different parts of it, and had no luck. I’m trying to make a sort of “wall-hug” npc function, to do obbies like this:


If you don’t know how to do this, you basically use shift lock, line yourself up with the part, and then slowly change your camera in the direction you want to go to get there. The problem with NPCs is, well, they don’t have “shift-lock”, and (as far as I know, if I’m wrong, please tell me) I can’t just emulate movement. (Like “W” presses). I’m not even sure if this is possible, but I’ve been trying for quite a while. I’m just wondering if anyone has ever done anything like this successfully?

Here's my currently sort-of messy code, and it's my best attempt at making this work
--Services

--Other
local obbyModel = game.Workspace.ObbyTest

local npcClone = game.ReplicatedStorage:WaitForChild("Dummy"):Clone()
npcClone.HumanoidRootPart.Position = obbyModel.StartPart.Position + Vector3.new(0,4,0)
npcClone.Parent = game.Workspace
npcClone.Humanoid:MoveTo(obbyModel.Path1.Position)
local jumped = false
local endTouched
local loopTimes = 0
local function testJump(humanoid)
	humanoid.Jump = true
	jumped = true
end

obbyModel.JumpPart.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		testJump(hit.Parent.Humanoid)
	end
end)
repeat wait() until jumped == true
npcClone.Humanoid:MoveTo(obbyModel.Path2.Position)
wait(.15)
--Wallhug
local animator = Instance.new("Animator")
animator.Name = "Animator"
animator.Parent = npcClone.Humanoid
local animationInstance = Instance.new("Animation")
animationInstance.AnimationId = "rbxassetid://7148106034"
animationInstance.Parent = npcClone.Humanoid
while true do
	npcClone.HumanoidRootPart.Orientation = Vector3.new(obbyModel.BackWallTop.Orientation.X ,obbyModel.BackWallTop.Orientation.Y + 180,obbyModel.BackWallTop.Orientation.Z )
	npcClone.Torso.Orientation = Vector3.new(obbyModel.BackWallTop.Orientation.X ,obbyModel.BackWallTop.Orientation.Y + 180,obbyModel.BackWallTop.Orientation.Z )
	npcClone.Humanoid:MoveTo(Vector3.new(npcClone.HumanoidRootPart.Position.X,npcClone.HumanoidRootPart.Position.Y,npcClone.HumanoidRootPart.Position.Z + 1))
	--local loadedAnimation = animator:LoadAnimation(animationInstance)
	--loadedAnimation:Play()
	--loadedAnimation.Stopped:Connect(function()
	--	--npcClone.HumanoidRootPart.CFrame = npcClone.Torso.CFrame
	--end)
	--loadedAnimation.Stopped:Wait()
	
	--npcClone.Humanoid:MoveTo(obbyModel.PathfindingGoal.Position)
	wait()
end

wait(5)

wait(1)

And I’m not using animations because I cannot include jumping and gravity as a factor, and it just needs to be really precise if that was a thing as well

I was able to come up with something because there is a certain angular limit to grip so as long as you don’t go past that limit, your dummy should be able to pass the ladder slide.

local runService = game:GetService('RunService')

local humanoid = script.Parent.Humanoid
local humanoidRootPart = script.Parent.HumanoidRootPart

local sidewaysDirection = humanoidRootPart.CFrame.LookVector + Vector3.new(0,0,0.3) -- I find 0.2-0.3 works best but you can experiment. Highest I've got to work was 0.325

while true do
	humanoid:MoveTo(humanoidRootPart.Position + sidewaysDirection)
	runService.Heartbeat:Wait()
end
1 Like

This looks great, is it possible that you could make sure it works with a jump before though?

Do you mean making the dummy jump onto the ladder?

1 Like

Yes, that’s what is supposed to happen in the game, sorry I didn’t explain that

1 Like

You’d have to make it jump into the ladder at a relatively flat angle but it seems to work.

local runService = game:GetService('RunService')

local humanoid = script.Parent.Humanoid
local humanoidRootPart = script.Parent.HumanoidRootPart

local sidewaysDirection = humanoidRootPart.CFrame.LookVector + Vector3.new(0,0,0.3) -- I find 0.2-0.3 works best but you can experiment. Highest I've got to work was 0.325

local position = Vector3.new(-18.5, 11.5, -25.5) -- this is the HRP's position but advanced a few studs so it has a distance to jump to

humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
humanoid:MoveTo(position)

humanoid.MoveToFinished:Wait()

while true do
	humanoid:MoveTo(humanoidRootPart.Position + sidewaysDirection)
	runService.Heartbeat:Wait()
end