Hi there!
I'm currently having issues with AC's pathfinding system. The game I'm working on has movement along lines (think Pentiment, or a traditional 2D sidescroller). The player moves purely in two-dimensions, only moving up or down when meeting with a sloping path. Currently, we are using straight-to-cursor movement (to allow the ability to click-and-hold for movement too) and a very thin navmesh (as thin as we can make it) in the shape of our path with the player's origin sandwiched between it. This works for the most part but often causes pathfinding issues as the player is constantly fighting against the top and bottom of the navmesh, with it just being a very thin box, and therefore is stutter-y and inconsistent.
What would be the best method for going about fixing this? Obviously we could use a custom movement script and just use standard colliders and gravity, but want to make sure our movement is as integrated into AC as possible so as to not lose all the support that gives us with animation, SFX, cutscenes etc.
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
Welcome to the community, @cruddish.
This being a visual issue, can you share any screenshots that show the scene's layout?
Likely the best way to handle this is a custom script that modifies the positions of the pathfinding points.
A script along these line can be found on the AC wiki here:
https://adventure-creator.fandom.com/wiki/2D_point_and_click_along_one_axis
This only works along the horizontal axis, but should be possible to modify to work for vertical at certain points. Give it a try and see if it's the right fit, first however.
Thank you for getting back @ChrisIceBox! I've attached an imgur link with some screenshots of an example scene. You can see that the path has curves/ramps, and a closeup of the navmesh simply being a thin box. The playerStart2D is placed inside it.
As for the script you sent, I can't get my head round it. Do you have any suggestions for how it could be modified to allow the player to interact with sloping navmeshes, or another way to get the player to only walk along direct lines (a la splines?). Thank you!
Screenshots
Thanks for the screenshots. It's a bit different to what I imagined, so the script above may not be the best approach after all.
Unity has a Splines package that may be useful here. I'll do some digging and see if there's a better method involving this. Park with me for the moment, and I'll report back.
Splines was one of initial methods of creating movement we tried, but we weren't sure how to fluidly incorporate it into Adventure Creator. Thank you for taking the time to look into it
It's fairly basic, but a script that'll keep character movement to a Spline can be found here:
https://adventure-creator.fandom.com/wiki/Snap_characters_to_Splines
Thank you so much so far this works great! Will let you know if we run into any problems. Additionally, is there an easy way to make it so the player character will not move unless the mouse click is a sufficient distance away from it? (i.e the mouse click must be a few units away before the player will move towards it). I've found that the pathfinding somewhat freaks out if the player clicks too close to the player character.
Is that a behaviour onle seen with Splines?
Try lowering the Settings Manager's Destination accuracy slider - this value determines how close is "close enough".
It's a behaviour we saw even with navmeshes, but I think now it's mostly just the walk animation looping every time the pathfinding updates when the player is clicking-and-holding on the position where the player character is already standing. Increasing the pathfinding update time decreases how often this animation loop happens but that number needs to be as low as possible for the click-and-hold movement to work fluidly. As it is, the player looks very gittery as the animation constantly loops, but this isn't a problem that occurs when the character is actually moving. Hopefully that makes sense?
To reiterate on the above comment, a similar issue seems to occur if trying to move beyond the spline (when the character hits a wall).
Try switching your Pathfinding method to A Star 2D, which is a faster algorithm. Does that make a difference?