Pathfinding Issue: Custom Rig Getting Caught On Corners

This is a support category for asking questions about how to get something done on the Roblox websites or how to do something on Roblox applications such as Roblox Studio.

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

I want to stop the rock monster in my game from getting stuck on corners.

I am wondering whether I am using Roblox’s pathfinding system appropriately or if I am doing something wrong that is causing it to have these problems.

  1. What is the issue? Include screenshots / videos if possible!

Also, here is the script I am using, which is being fired every frame via heartbeat service:

--should path to the player
local function pathTo(sentinelPos, playerPos)
	
		
	local path = game:GetService("PathfindingService"):CreatePath({

		AgentRadius = 6,
		AgentHeight = 12.5,
		AgentCanJump = false,
		AgentCanClimb = false,
		WaypointSpacing = 6
	})


	local success, errorMessage = pcall(function()

		path:ComputeAsync(sentinelPos, playerPos)
	end)

	if success then

		local waypoints = path:GetWaypoints()

		for i = 1, table.maxn(waypoints), 1 do 

			sentinel.Humanoid:MoveTo(waypoints[i].Position)

			sentinel.Humanoid.MoveToFinished:Wait()
		end
	end
end

This is a custom rig which I built using Arch Mages “Rig Edit Lite” plugin, not sure if this would interfere with Roblox’s pathfinding system.

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I have tried setting the agent radius to a lot of different values; I did measure this agent radius it is correct.

I have tried firing the path finding less than every single frame, which did not really change the result.

I made my own pathfinding system that was extremely flawed and I am hoping to move back to the roblox pathfinding system as I believe I am just misinterpreting its functionality.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

One important thing I have noticed is that it seems to get a path that works great, then as it is navigating that path it begins to take shortcuts that should not be allowed according to the parameters I have given it. I am trying to keep the pathfinding as simple as possible; I do not care if the rock monster turns a corner in a non-smooth manerism. I just really, really want it to stop getting caught on corners.

I have heard about A* (A times or A star) pathfinding, but I am not sure whether I can use this in roblox, since I read lua is too slow to make its own grid for pathfinding. I am also fairly sure this is not a 3D solution, and I would like it to be, though it does not absolutely have to be 3D if the pathfidning is high enough quality (doesn’t get caught on corners).

Any help with this is sincerely appreciated as this is the last major obstacle to developing my game, I am really really stuck here, and I am so grateful for anyone who can help me out here.

REALLY IMPORTANT NOTES:

  • I was not referencing the feet of the player and the rock monster which is necessary for pathfinding as the ComputeAsync expects the point at the humanoid at ground level.

  • Setting the humanoid to can collide and USING HIP HEIGHT was something which I was not doing which was causing the rock monster to get caught on ramps and other objects.

  • Every other part in the rig should have can collide disabled, if you want your monster to still physically interact with players im fairly sure you can use collision groups.

In summary, I made a lot of mistakes regarding how I used the pathfinding. I recommend using axolotl’s solution and slender bandits solution in combination with the hip height thing that I wasn’t doing. Use the feet position of the humanoids by getting the root part position and subtracting the hip height from the Y Value of the root parts position. All of these things should durastically improve the humanoids ability to navigate and pathfind!

1 Like

Bumping this post because I really need help here, I am very lost.

Hey man, RogueAxolotl here! So I am relatively new to game development in general. However, I have come a good way in the past year or so - maybe I can help. I actually am just now having the same issue, that’s how I found this post. I saved it in case someone found a fix. Good news and bad news… I found a simple fix but it isn’t totally reliable, as it sometimes doesn’t work (but most of the time does. Maybe I didn’t do it right though). Without further ado, let me explain! :smiley:

The possible fix: You can add a pathfinding modifier to a slightly larger wall. To do this, you can duplicate your current wall and make it slightly larger (maybe a stud or two, perhaps quite a few due to the size of your rock guy (play around with how many studs for the size of the duplicate wall)). Now, anchor the wall, change the transparency to 0 (so it isn’t visible), maybe turn off can collide (not sure if this helps or not, but I think it might?), and then insert a pathfinding modifier. Then go into the pathfinding modifier’s properties and change the “Label” setting to whatever you want it to be called inside your code.

After all of that, try using this code where I added in some costs. Inside the costs, type in the label you used. Now to my knowledge, you can actually insert a pathfinding modifier into any other part and change the “Label” property to the one you set in “Costs” inside this script, and with the code I am showing you, it should avoid any part with that label, but expect it to not be totally reliable all the time.

local path = game:GetService("PathfindingService"):CreatePath({

	AgentRadius = 6,
	AgentHeight = 12.5,
	AgentCanJump = false,
	AgentCanClimb = false,
	WaypointSpacing = 6,
	Costs = {
		AvoidThis = math.huge --You can change this to whatever your label is inside the pathfinding modifier
	}
})

This should work for you! If it does, awesome! If it doesn’t, feel free to ask me some questions on it. As said before, I am still pretty new to development as a whole. But this is what has worked decently well for me. I don’t want to take all the credit if this does work - it is a solution I found, not created (but I did a lot of research and redesigned the solution to what I wanted). I can’t find the original poster for the solution (I did a crazy amount of research to event find it so I can’t remember it either), but credits to them all the way! Anyway, have a great day and God bless! Hope this works for you dude! Also, that rock guy is AMAZING!!! :slight_smile:

Edit: So, I tested this method again today. It doesn’t work well in small spaces (regardless if the NPC is able to completely fit, and even have some extra room, inside that small space. I think it could have a chance of working in a small space with some optimization though

2 Likes

Thank you so much, I am going to give this a shot; I am fairly sure I will be marking this as the solution though. I am also new to development, though I am extremely new, and I have not gotten to try many tools such as pathfinding here.

The rock guy definitely does not need to be in small spaces, he is very large, and I wont be trying to fit him anywhere since he is more of a defender than an attacker. Thank you for testing that though, much appreciated!

Also thank you sincerely for the compliment regarding the rock monster; kindness goes an extremely long way and has helped me with this project a lot. Thank you, SO MUCH, for the response!

2 Likes

No problem! As you marked my post as a solution, I am guessing it has worked, and that is epic! To be honest with you though, I had been testing the small spaces in my own project and then found out it was an issue, so I didn’t think to test it for this post :sweat_smile:

Have an amazing time with your project man! Something I forgot to add in the last post, my reaction to first seeing it was like “WHOAAAAAA” (literally, and my jaw dropped too). It truly looks awesome! Keep up the good work and have a blessed day! :smiley:

2 Likes

agent radius and agent height dont work.

I’m having a similar problem but with a more detailed rig getting frozen whenever it hits something but I think for your rig you can just disable all its collisions except for its humanoid root part and it will work. I know you already marked a post as a solution but if its any easier than there you go!

1 Like

It might be less asthetically pleasing if the monster clips through the wall though. Do you set the humanoid root part to be the size of the monster? (ie, acting as its hitbox?). I believe this is another strong solution to this problem, and I am wondering if agent parameters (height, radius, etc) are only considered with the dimensions of the humanoid root part, and not the rig its attached to?

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