Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

AI [Released] PathBerserker2d - 360° platformer pathfinding

Discussion in 'Tools In Progress' started by PathBerserker2dDev, Jul 14, 2020.

  1. PathBerserker2dDev

    PathBerserker2dDev

    Joined:
    Jul 14, 2020
    Posts:
    47
    Okay this is weird. Unity has only send me an email to notify me of your last post GiomGots.
    I have to remove the link to this thread from the store page I think. Direct email will be more reliable.

    I'll go through all of the recent posts asap.
    I'm very sorry.
     
  2. PathBerserker2dDev

    PathBerserker2dDev

    Joined:
    Jul 14, 2020
    Posts:
    47
    You can either use a NavSegmentSubstractor (https://oribow.github.io/PathBerser...PathBerserker2d_1_1NavSegmentSubstractor.html) if you want to remove the navigation at that point permanently while baking.

    Or you can use NavAreaMarker (https://oribow.github.io/PathBerser...on/classPathBerserker2d_1_1NavAreaMarker.html) if you want to move/remove the obstacle at runtime. Or want certain characters to ignore the obstacle.
     
  3. PathBerserker2dDev

    PathBerserker2dDev

    Joined:
    Jul 14, 2020
    Posts:
    47
    I think you wrote me a direct email with the same topic, which I answered. So I think this is solved. If not, please write me again.
     
  4. PathBerserker2dDev

    PathBerserker2dDev

    Joined:
    Jul 14, 2020
    Posts:
    47
    Hi,
    not sure if you haven't seen, but I have send you a pm.
     
  5. Ulugbek_UGD

    Ulugbek_UGD

    Joined:
    May 16, 2019
    Posts:
    3
    It's a shame that I was not able to use this in Unity 2018((
    apparently did not support it all the same.
    I know this is not the package's fault and that it works fine in newer versions of Unity
    but my game has been created for a long time in Unity 2018.
    Can I somehow make this awesome asset work with Unity 2018?

    sorry for my English
     
  6. PathBerserker2dDev

    PathBerserker2dDev

    Joined:
    Jul 14, 2020
    Posts:
    47
    There is only one roadblock that stands in the way of supporting a unity version before 2019. But its a major one.

    https://docs.unity3d.com/ScriptReference/Collider2D.CreateMesh.html
    Does not exists prior to 2019. Without it, my asset can't generate the nav shape from the 2d colliders.
    It would be possible to rewrite this function per hand, but that is quite some work.

    So here is a deal. If you (or anyone else) can write an implementation of Collider2D.CreateMesh that works like the 2019 version, then I will integrate it and publish a 2018 version of my asset and give you a free copy!
     
  7. Ulugbek_UGD

    Ulugbek_UGD

    Joined:
    May 16, 2019
    Posts:
    3
    Yes, you are right, it may not be the easiest way.
    Easier to update the engine.
    Thanks for the answer anyway!
    and thanks for the development of PathBerserker2d !, as there are very few opportunities to give life to 2D NPCs these days.

    and yes, it would be very cool if you add NodeCanvas or FlowCanvas integration.
    With the help of which it would be possible to refer to agents through the NodeCanvas.
    eg:
    Go, Wait, Follow, Interrupt Target or Path, Change. etc
    This can be done in the usual way through C #, but when you prototype a game, quickly building logic through visual programming just saves!
    yes that would be very cool...
     
  8. foobooio

    foobooio

    Joined:
    Oct 14, 2018
    Posts:
    5
    Will this work with webgl?
     
  9. PathBerserker2dDev

    PathBerserker2dDev

    Joined:
    Jul 14, 2020
    Posts:
    47
    foobooio likes this.
  10. grinsmilestudio

    grinsmilestudio

    Joined:
    Aug 11, 2021
    Posts:
    1
    Hi, I would like to ask. Is there any requirement version for Corgi?
     
  11. PathBerserker2dDev

    PathBerserker2dDev

    Joined:
    Jul 14, 2020
    Posts:
    47
    Hi, sorry for your wait. I just don't get any emails for this thread anymore. IDK why.
    If this still matters, Corgi support was developed with Corgi v6.7. I'd guess it works with newer and older versions, but I'm not sure. If you find it not working for you, I'm happy to look into fixing it or offer a refund.

    For OTHERS who want to ask me a QUESTION: Please write me an email as a sure fire way to get an answer quickly.
     
  12. yehiaserag

    yehiaserag

    Joined:
    Mar 8, 2018
    Posts:
    6
    I've sent you an email about a bug that I faced in baking, do you still check the mail or do I have to message you here?
     
  13. PathBerserker2dDev

    PathBerserker2dDev

    Joined:
    Jul 14, 2020
    Posts:
    47
    Hi,
    I usually reply to emails within a day or two. Can you PM me your Email address? Maybe I overlooked your mail or it went missing somewhere.
     
  14. squiDan

    squiDan

    Joined:
    Apr 27, 2022
    Posts:
    4
    Hi,

    First of all, kudos on the asset, It helped me tremendously setup my character’s movement and navigation around the level.

    Now on the the issues:

    I’ve emailed you twice in the past couple of weeks and haven’t heard back. Maybe I’ll have better luck here in the forums.

    I’ve integrated PathBerserker2d into my game and I ran into an error that I believe is a bug in your code. Could you please look into it? Unity throws a KeyNotFoundException whenever I disable a GameObject that contains a NavSurface and NavLink components in them.

    Steps to Reproduce:
    1. Open the complete_example scene included in PathBerserker2d.
    2. Run the game.
    3. Select Moving Platform Tower Surface GameObject in the Hierarchy panel.
    4. Click on the checkbox in the Inspector panel to disable the selected GameObject.

    Result:
    The following error appears in the console.

    KeyNotFoundException: The given key was not present in the dictionary.
    PathBerserker2d.NavGraph.RemoveSoftRefLink (PathBerserker2d.INavLinkInstance link, PathBerserker2d.NavSurface targetSurface) (at Assets/PathBerserker2d/Scripts/PathBerserker2d/NavGraph/NavGraph.cs:514)
    PathBerserker2d.NavGraph.InternalRemoveNavLink (PathBerserker2d.INavLinkInstance link, PathBerserker2d.NavSegmentPositionPointer start, PathBerserker2d.NavSegmentPositionPointer goal) (at Assets/PathBerserker2d/Scripts/PathBerserker2d/NavGraph/NavGraph.cs:527)
    PathBerserker2d.NavGraph+RemoveNavLinkChange.Apply (PathBerserker2d.NavGraph graph) (at Assets/PathBerserker2d/Scripts/PathBerserker2d/NavGraph/NavGraph.cs:693)
    PathBerserker2d.NavGraph.Update () (at Assets/PathBerserker2d/Scripts/PathBerserker2d/NavGraph/NavGraph.cs:101)
    PathBerserker2d.PBWorld.Update () (at Assets/PathBerserker2d/Scripts/PathBerserker2d/PBWorld.cs:75)

    Expected Result:
    The GameObject is disabled without any errors.

    This is urgent because your asset is a fundamental piece on my game and this is currently a blocker.

    The other feedback I have is that the documentation could be improved.

    Thank you so much!
     
  15. PathBerserker2dDev

    PathBerserker2dDev

    Joined:
    Jul 14, 2020
    Posts:
    47
    Hi,

    I haven't received you mails, but got the notification for your post on here. I don't know why that happens sometimes. I have received emails from other people in the last weeks just fine. I've reproduced this error and fixed it. Update should becoming the next couple of days.
    Thanks for your patience. Also very much thank you for the detailed bug report. Made it a breeze to find the issue.

    Cheers
     
  16. squiDan

    squiDan

    Joined:
    Apr 27, 2022
    Posts:
    4
    Thanks for the quick turn around releasing the update. I already got it.

    Well, that's concerning. Did you check your spam folder? I've emailed you explicitly because you said here in the forums and on your asset product page to do so because you have problems receiving messages and that email would be best. And now you're saying sometimes you don't get those either. Please look into that, because it's not very reassuring to think that we may or may not be able to get a hold of you.


    I can confirm that the error I reported has been fixed. But there are more. Please check your inbox and look for an email title MissingReferenceException and KeyNotFoundException when SceneManager.LoadScene is called . I'm trying to avoid posting snippets of your source code in the forums.

    Thanks for your time!
     
  17. PathBerserker2dDev

    PathBerserker2dDev

    Joined:
    Jul 14, 2020
    Posts:
    47
    Ah there it is. I feel really stupid now for never bothering to look in the spam folder. Yeah, your emails where flagged as spam. I can see all 3 of them now. Lets continue this via email then.
     
    squiDan likes this.
  18. squiDan

    squiDan

    Joined:
    Apr 27, 2022
    Posts:
    4
    No worries. It happens ;). The errors I reported have all been fixed as of v2.4.5. Thank you very much for your support @PathBerserker2dDev!
     
  19. fabiopov_1

    fabiopov_1

    Joined:
    Jan 2, 2018
    Posts:
    11
    Hello everyone,
    whenever I try to generate a navmesh, regardless of unity version and operating system I always get this error :

    Mesh '': abnormal mesh bounds - most likely it has some invalid vertices (+/-inifinity or NANs) due to errors exporting.
    Mesh bounds min=(-nan(ind), -nan(ind), 0.00), max=(-nan(ind), -nan(ind), 0.00). Please make sure the mesh is exported without any errors.


    This basically makes the product useless!
    I've already written an email to support but still unfortunately i haven't received a reply.
    Does anyone else have the same problem?
     
  20. chloelcdev

    chloelcdev

    Joined:
    Sep 19, 2021
    Posts:
    7
    I've sent an email as well but this asset seems to break down when using Rigidbody2D with gravity, is there a workaround for this? We use gravity for enemy blow-back.
     
  21. Joywayer

    Joywayer

    Joined:
    Feb 1, 2021
    Posts:
    5
    Hello, Tilemap bake problem,just part of platform bake success Unity_apf6nAzK03.png
     
  22. Joywayer

    Joywayer

    Joined:
    Feb 1, 2021
    Posts:
    5
    Another question,How can i get random goal on segment where player stand on
     
  23. PathBerserker2dDev

    PathBerserker2dDev

    Joined:
    Jul 14, 2020
    Posts:
    47
    I can't really say what it is based on that screenshot alone. Can you send me an example scene with the problem occurring? Either here in the thread or per email. Would help a lot.

    To move to a random section you can use this function:
    https://oribow.github.io/PathBerser...vAgent.html#aabb985b704548b27938bbdd234eacc3b
    To get a random section you can use this function: https://oribow.github.io/PathBerser...BWorld.html#af42419f602ef14eeabc56655a1d21f82 Although, keep in mind that this point may not be reachable from the player's current position or the player may not be able to stand on it, because the ceiling is too low. Look at the above NavAgent's random walk function for an example on how to use it despite these limitations.

    A different approach might be to generate a random point yourself and use https://oribow.github.io/PathBerser...BWorld.html#a4b98c59ae4be6beb58154844571cd87a to map it to a segment. Since that function takes in a NavAgent as parameter, the resulting point is guaranteed to be a valid position for the agent.
     
  24. Joywayer

    Joywayer

    Joined:
    Feb 1, 2021
    Posts:
    5
    Thanks for your reply.This is my example scene (Scenes/SampleScene).in project .
     

    Attached Files:

  25. Joywayer

    Joywayer

    Joined:
    Feb 1, 2021
    Posts:
    5
    How can i know about NavAgent can or not reach goal
     
    Last edited: Jun 8, 2023
  26. PathBerserker2dDev

    PathBerserker2dDev

    Joined:
    Jul 14, 2020
    Posts:
    47
    Thanks! I have taken a look at it and discovered somethings in the code that were not working as expected. I've fixed it up and just submitted an update to the store. It should be live in a few days.

    I'm adding a convenience function for it in the NavAgent class in this release. That's what it will look like:
    Code (CSharp):
    1. /// <summary>
    2. /// Convenience function that will return if the agent could reach the given point from it's current location. It runs synchronously which is not optimal for performance.
    3. /// </summary>
    4. public bool CanReach(Vector2 goal)
    5. {
    6.     var pr = CreatePathRequest(Position, goal);
    7.     PBWorld.PathTo(pr);
    8.  
    9.     while (pr.Status != PathRequest.RequestState.Finished && pr.Status != PathRequest.RequestState.Failed)
    10.     {
    11.         // fast spinning
    12.     }
    13.     return pr.Status == PathRequest.RequestState.Finished;
    14. }
     
  27. Joywayer

    Joywayer

    Joined:
    Feb 1, 2021
    Posts:
    5
    Thanks!
     
  28. pepsi4

    pepsi4

    Joined:
    Mar 1, 2016
    Posts:
    8
    Hello! Can I remove this corner links? Or fix the path. So my NPC would not stop to change angle in that obvious way? I use polygon collider instead of box collider. upload_2024-1-19_19-58-23.png

    Path for NPC looks like this, and he stops to change the rotation. upload_2024-1-19_20-25-15.png

    upload_2024-1-19_20-25-46.png

    As a small fix to this I think that I can use Nav Links to jump over this area.
     
    Last edited: Jan 19, 2024
  29. s_marcell

    s_marcell

    Joined:
    Mar 22, 2018
    Posts:
    20
    I was trying to achieve the same thing: get a point that is guaranteed to be reachable by the navagent (aka the point HAS to be on the same NavSurface the agent is on). What I did was I used the navagent's
    currentMappedPosition.surface
    field and copy pasted the existing code from
    NavGraph.GetRandomPointOnGraph()
    except the part where it finds a random surface.

    It looks like this:

    Code (CSharp):
    1. public static Vector2 GetRandomPointOnSurface(NavSurface surf)
    2. {
    3.        var seg = Utility.WeightedRandomChoice(surf.NavSegments,
    4.            surf.NavSegments.Select(s => s.Length), surf.TotalLineLength);
    5.  
    6.        var t = UnityEngine.Random.Range(0, seg.Length);
    7.  
    8.        return surf.LocalToWorld(seg.GetPositionAlongSegment(t));
    9. }
    It seems to be working and up until now I haven't seen any unwanted behaviour.

    Can you confirm this is a valid approach?
     
  30. PathBerserker2dDev

    PathBerserker2dDev

    Joined:
    Jul 14, 2020
    Posts:
    47
    Hi. Corner links are non-removable. Without them the agent wouldn't know how to get from one segment to the other.
    You have a few options:
    - increase corner traversal speed to make the rotation faster
    - uncheck the "Enable Agent Rotation" flag to skip all rotation entirely (will spam some null ref errors currently, but those don't affect anything and I'll have that fixed)
    - uncheck "Corner Links" from "Enabled Features" and write your own handler that could take the angle of the corner into account to either rotate or not

    Hi. Yes that certainly looks right. Some issue you could run into would be:
    - NavAreaMarkers may still prevent an Agent from reaching a position
    - NavLinks could be non-traversable for that Agent or turned off at that moment, preventing an Agent from reaching a position
    - Other connected surfaces are of course excluded, but that only matters if you use multiple

    The hard truth of pathfinding is that it's impossible to decide if a given position is reachable without doing the whole pathfinding. The most reliable way would be to use
    NavGraph.GetRandomPointOnGraph()
    , issue a pathfinding request to that point, wait a few frames till it's done, and then either reroll a new point or start moving.
    That can introduce considerable delay till the agent starts moving though. There is no upper bound of how much time that would take. I wouldn't recommend doing that.
    If your world is static, then you as a level designer could place down some points that you know will be reachable and at runtime let the agent roll a dice to move to one of these pre-placed points.
    The approach with only searching on the same NavSurface could be a pretty good optimization depending on how your game is setup.
    Point is, the really correct way of doing random point walking sucks and you gotta find some sort of clever work around, the specifics of which highly depend on the specifics of your game.
    Hope that helps.
     
    s_marcell and pepsi4 like this.
  31. s_marcell

    s_marcell

    Joined:
    Mar 22, 2018
    Posts:
    20
    Awesome thanks for the feedback!

    One more thing I'm finding difficult to handle is to know when the agent has reached its goal. I know that there is an event called
    OnReachedGoal
    but sometimes listening for an event is not applicable and something more traditional is requried, like a distance check. However
    PathTo()
    seems to need more time to update the goal and doing the distance check the same frame it was called may result in an immediate success, because for instance the agent is at the previous goal's location.

    Could you please direct me to a more reliable way of doing this?
     
    Last edited: Jan 22, 2024
  32. PathBerserker2dDev

    PathBerserker2dDev

    Joined:
    Jul 14, 2020
    Posts:
    47
    The way I did it in the GoalWalker script was by storing the goal in the script and not use the NavAgent's path variables. Like you said, those take a few frames to update, because it takes time for the path to be found.
    Code (CSharp):
    1.  [SerializeField]
    2.         public NavAgent navAgent;
    3.         [SerializeField]
    4.         Transform goal = null;
    5.  
    6.         void Update()
    7.         {
    8.             // are we not close enough to our goal and not already moving to its position
    9.             if (Vector2.Distance(goal.position, navAgent.transform.position) > 0.5f && (navAgent.IsIdle || goal.hasChanged))
    10.             {
    11.                 goal.hasChanged = false;
    12.                 navAgent.UpdatePath(goal.position);
    13.             }
    14.         }
    That's pretty much the best way. I guess you could use the a currentPathRequest field, which does get updated immediate after a call to PathTo(), but that field isn't exposed. It could also contain multiple goals, if PathTo was called with multiple goals. I'm not sure if that really helps that much. Whatever code is calling the PathTo function knows the goal immediately, so it shouldn't be hard to store that somewhere for distances checks?
    Maybe it makes sense to adjust the PathGoal property to use the pathRequest's goal, if it is pending. Although I have no clue how to handle pathrequests to multiple goals. Which should be returned? Also not sure if that would be a breaking change for other people. I do like the idea, since it would behave a little more like one would perhaps expect. But again, how to handle multiple goals?
     
  33. pepsi4

    pepsi4

    Joined:
    Mar 1, 2016
    Posts:
    8
    Hello! Thank you for your great asset. I`m using PB + Corgi.

    Can I make my agent jump through corner links using CorgiBasedMovement.cs , like it jumps in TransformBasedMovement.cs? In corgi — jump`s height not changes on links, but using TransformBasedMovement I can change jump`s height by set up link parameters.
     
  34. PathBerserker2dDev

    PathBerserker2dDev

    Joined:
    Jul 14, 2020
    Posts:
    47
    No, there is no build-in way to do so. You can modify the movement code to adjust the jump force yourself however. It's probably gonna be a bit of challenge to get the tuning between jump force and actual jump height + distance covered correct though.
    Sorry.
     
    pepsi4 likes this.
  35. pepsi4

    pepsi4

    Joined:
    Mar 1, 2016
    Posts:
    8
    Hello! Can I change NavMeshAgent position check to RayCast check? My NavMeshAgent sticks to the agent`s foot, and because I have different colliders and not the straight ones, the agent sometimes could not build the path, (NavMeshAgent position appears under or below the traversable surface). Where can I find the condition in code, coz I am lost a little. PathBerserker2dDev
     

    Attached Files:

    Last edited: Apr 11, 2024